mIRC Home    About    Download    Register    News    Help

Topic Options
#29963 - 16/06/03 01:03 AM /bench command for speed testing.
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2541
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
_________________________
At least I won lunch.
Good philosophy, see good in bad, I like!

Top
#29964 - 16/06/03 03:22 AM Re: /bench command for speed testing.
coolspot Offline
Babel fish

Registered: 03/03/03
Posts: 50
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.

Top
#29965 - 16/06/03 07:33 AM Re: /bench command for speed testing.
trenzterra Offline
Fjord artisan

Registered: 10/12/02
Posts: 196
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

}
_________________________
trenzterra
AustNet #trenzterra and #w
Head Scripter @ http://trenzterra.uni.cc

Top
#29966 - 16/06/03 08:37 AM Re: /bench command for speed testing.
KingTomato Offline
Planetary brain

Registered: 04/01/03
Posts: 3012
Loc: New Hampshire, USA
until then,

var %star = $ticks

...blah...

/echo -a Time Elapsed: $calc($ticks - %start) $+ ms
_________________________
-KingTomato

Top
#29967 - 16/06/03 11:07 AM Re: /bench command for speed testing.
theRat Offline
Hoopy frood

Registered: 11/12/02
Posts: 774
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
}
 
_________________________
Code:
//if ( khaled isgod ) echo yes | else echo no

Top
#29968 - 16/06/03 12:44 PM Re: /bench command for speed testing.
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2541
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
_________________________
At least I won lunch.
Good philosophy, see good in bad, I like!

Top
#29969 - 29/08/03 02:42 AM Re: /bench command for speed testing.
cold Offline
Hoopy frood

Registered: 25/02/03
Posts: 810
Loc: Brazil
I strongly second that suggestion. About trenzterra said, calling an alias from the bench command should do the job..
_________________________
* cold edits his posts 24/7

Top
#29970 - 29/08/03 03:12 AM Re: /bench command for speed testing.
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2541
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
_________________________
At least I won lunch.
Good philosophy, see good in bad, I like!

Top
#29971 - 03/09/03 03:44 PM Re: /bench command for speed testing.
_CyRuSS_ Offline
Pikka bird

Registered: 02/09/03
Posts: 18
Loc: Dublin, Ireland
I have been wanting a command like this added too, hope its added.
_________________________
______________
Kiss me, I'm Irish!

Top
#29972 - 06/09/03 12:39 PM Re: /bench command for speed testing.
cold Offline
Hoopy frood

Registered: 25/02/03
Posts: 810
Loc: Brazil
Yeah, I see I have to agree that this would be of much better use instead of having to break it up into aliases.
_________________________
* cold edits his posts 24/7

Top