Use $ticks for this. $ticks returns the number of milliseconds since your last boot. The idea is to record the $ticks value before the specified routine is run, then record $ticks again after the routine is finished. Subtracting the first number from the second tells you how many milliseconds your routine needed to complete. Example:
var %a = $ticks
echo -s /myalias took $calc($ticks - %a) msecs to complete.
Of course, there can be anything between the 1st and the 3rd line, not just a single alias. The advantage of this method is that $ticks will always keep increasing once every millisecond, regardless of what you do in mirc, because its value is updated by Windows. This makes it accurate enough for your purposes.
In case you want to compare the speed of two aliases that have similar performance, you can use the same method but instead of calling each alias once, you call it a large number of times by putting it in a while loop. This way, the speed difference is multiplied by N (where N is the number of iterations in the loop), so it shows up. For example, if the difference in speed between two aliases is 1 msec, then in 1000 iterations, it becomes 1000 msecs, which makes the result safe enough. Remember that a few milliseconds difference isn't safe enough to compare the speed of two aliases, because of fluctuations in their execution time. For example, an alias might take 13 msec once and 16 msec next time. If another alias takes 14msec and 15 msec respectively, there's no way to tell which is faster. Putting both in a loop will make any existing difference show up.
When benchmarking anything in mirc, try to benchmark only the part of the code that interests you, making sure you have the least possible number of irrelevant variable assignments, if statements etc in between. Make sure that %a is set to $ticks right before the code you want to benchmark and that the new $ticks value is grabbed right after the the code is finished. If you want to echo the result at a later time, set a second local variable to $ticks after the routine finishes and use $calc(%b - %a) later.
In case two routines are very
similar, speed-wise, things get a little harder and a lot of other factors must be taken into consideration when designing the benchmark. I won't get into details here, but remember that the accuracy of benchmarks in mirc is inherently limited.