in reply to How can I keep track of the execution time of a script?
That prints the run time of your script in seconds.# your script goes here BEGIN { $SIG{__DIE__} = sub { print + time() - $^T, $/, @_ } } print + time() - $^T, $/
Update: By the way, there is a module called Benchmark that is great for testing algorithms and routines and such. Turnstep wrote a great tutorial on it called Benchmarking Your Code
Update: For a variety of reasons, it is much better (and simpler too!) to use a single END block instead of the repition that I suggested. Thanks merlyn for pointing this out. (I also like the use of warn)
Also, If your script is taking longer then a minute or two, you might want to break down those seconds to be minutes:seconds, but don't forget the more work you do after that last call to time, the less accurate the stamp. (Well, time only has a granularity of a second... so you actually have plenty of room, but anyway...)
END { $a=time-$^T, warn sprintf "Runtime %d min %d sec\n", $a/60, $a%6 +0 }
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: How can I keep track of the execution time of a script?
by merlyn (Sage) on Oct 04, 2000 at 23:47 UTC | |
by Adam (Vicar) on Oct 04, 2000 at 23:48 UTC | |
RE: RE: How can I keep track of the execution time of a script?
by Sarcasmo (Initiate) on Oct 05, 2000 at 00:28 UTC | |
by Adam (Vicar) on Oct 05, 2000 at 01:05 UTC | |
by acid06 (Friar) on Oct 05, 2000 at 00:53 UTC | |
by Adam (Vicar) on Oct 05, 2000 at 00:58 UTC | |
by acid06 (Friar) on Oct 05, 2000 at 01:05 UTC |