mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
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


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Mar 2003
Posts: 50
C
Babel fish
Offline
Babel fish
C
Joined: Mar 2003
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.

Joined: Dec 2002
Posts: 196
T
Vogon poet
Offline
Vogon poet
T
Joined: Dec 2002
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
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
until then,

var %star = $ticks

...blah...

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


-KingTomato
Joined: Dec 2002
Posts: 774
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
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
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
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


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
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
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
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


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Sep 2003
Posts: 18
_
Pikka bird
Offline
Pikka bird
_
Joined: Sep 2003
Posts: 18
I have been wanting a command like this added too, hope its added.


______________
Kiss me, I'm Irish!
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
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

Link Copied to Clipboard