mIRC Homepage
Posted By: Raccoon /bench command for speed testing. - 16/06/03 12:03 AM
I tried posting this suggestion a couple weeks ago, then my computer crashed and I forgot all about it.

It would be nice if mIRC had a command for speed testing code using a high definition (multimedia) timer.

/bench [N] <code|alias|identifier>
$bench(<code|alias|identifier>,[N])

The /bench command would evaluate the code, alias, or identifier N times (1 by default), and output the time it took (in milliseconds) to process the specified code. The $bench identifier would work the same, but return the results.

Output of the code tested would be suppressed, including display output and commands sent to the server. Ideally, only simple routines would be tested, but to prevent display/server floods, all output would be suppressed. Perhaps some flags could be added to bypass this default in some extreme case where display output lag is a desired variable.

Examples:
/bench 10000 var %s = (abc) (def) (hij) | $regex(%s,/(\(.*?\))/g) | echo -a $regml(3)
/bench 10000 var %s = (abc) (def) (hij) | $regex(%s,/\(.*?\) \(.*?\) (\(.*?\))/) | echo -a $regml(1)
/bench 10000 var %s = (abc) (def) (hij) | $regsub(%s,/\(.*?\) \(.*?\) (\(.*?\))/,\1,%s) | echo -a %s


In each example, a regular expression and method is processed 10,000 times. The /echo -a display is surpressed, but included because the user wants to take the evaluation of $regml verse %s into consideration aswell. The output of /bench may look something like:

* Bench Results: 10000 iterations in 1931 ms

I know many people do this with var %ticks = $ticks and $calc($ticks - %ticks), I do too. But you usually end up writing a new speed testing routine for each circumstance, and worry about overhead from your WHILE loop and /inc. This overhead could be reduced significantly with internal looping. $ticks is also a fairly inaccurate timer, while a high resolution multimedia timer could be used internally.

Thanks for reading. Constructive criticism welcomed.

- Raccoon
Posted By: coolspot Re: /bench command for speed testing. - 16/06/03 02:22 AM
I love this idea. Soley for the fact that in many ways it can help someone improve thier coding skills by letting them see in real-time the results of thier code. This would be a feature that could have big implications on the amount of complex, well written scripts we see out there.
Posted By: trenzterra Re: /bench command for speed testing. - 16/06/03 06:33 AM
Nice feature I would want too.

Sometimes I have quite a big script I want to test how long it would take to do this and that.

but maybe for big scripts, something like this can be used:

bench {

script here

}
Posted By: KingTomato Re: /bench command for speed testing. - 16/06/03 07:37 AM
until then,

var %star = $ticks

...blah...

/echo -a Time Elapsed: $calc($ticks - %start) $+ ms
Posted By: theRat Re: /bench command for speed testing. - 16/06/03 10:07 AM
Code:
 
alias bench {
var %start = $ticks, %i = 1, %j = $iif($1 isnum,$1,1000), %cmd = $iif($1 isnum,$2-,$1-)
while ( %i &lt;= %j ) {
[ %cmd ]
;Should we use evaluation brackets here at all?
}
echo -a Time Elapsed for executing " %cmd " %j times: $calc($ticks - %start) $+ ms
}
 
Posted By: Raccoon Re: /bench command for speed testing. - 16/06/03 11:44 AM
Reprinted:
> I know many people do this with var %ticks = $ticks and $calc($ticks - %ticks), I do too. But you usually end up writing a new speed testing routine for each circumstance, and worry about overhead from your WHILE loop and /inc. This overhead could be reduced significantly with internal looping. $ticks is also a fairly inaccurate timer, while a high resolution multimedia timer could be used internally.

- Raccoon
Posted By: cold Re: /bench command for speed testing. - 29/08/03 01:42 AM
I strongly second that suggestion. About trenzterra said, calling an alias from the bench command should do the job..
Posted By: Raccoon Re: /bench command for speed testing. - 29/08/03 02:12 AM
Yep, that would be a cool use aswell... the ability to insert /bench into an existing script to test a segment of code without having to break it up into aliases.

Alias PLUGH {
  var %s = $1-
  xyzzy
  foo
  bench {
    code to
    speed test
    goes in here
  }

  yatta!
}

This method would display bench results for that segment of code in your status window. This could be useful inside of a while loop to see if your code is slowing down as the loop progresses, or to compare speed improvements between /write and /hadd, etc.

Perhaps an identifier $benched could return the results of the prior bench, so you can plot a graph or something. If you dont want results to appear in your status window, the '.' prefix could be used on .bench.

- Raccoon
Posted By: _CyRuSS_ Re: /bench command for speed testing. - 03/09/03 02:44 PM
I have been wanting a command like this added too, hope its added.
Posted By: cold Re: /bench command for speed testing. - 06/09/03 11:39 AM
Yeah, I see I have to agree that this would be of much better use instead of having to break it up into aliases.
© mIRC Discussion Forums