timethis - run a chunk of code several times
timethese - run several chunks of code several times
timeit - run a chunk of code and see how long it goes
timethis ($count, "code");
timethese($count, { 'Name1' => '...code1...', 'Name2' => '...code2...', });
$t = timeit($count, '...other code...') print "$count loops of other code took:",timestr($t),"\n";
use Benchmark; $t0 = new Benchmark; # ... your code here ... $t1 = new Benchmark; $td = timediff($t1, $t0); print "the code took:",timestr($td),"\n";
$Benchmark::Debug
flag:
debug Benchmark 1; $t = timeit(10, ' 5 ** $Global '); debug Benchmark 0;
Side-effects: prints out noise to standard out.
Returns: a Benchmark object.
clearcache
clearallcache
disablecache
enablecache
($real, $user, $system, $children_user, $children_system)
in seconds for the whole loop (not divided by the number of rounds).
The timing is done using time
and times.
Code is executed in the caller's package.
Enable debugging by:
$Benchmark::debug = 1;
The time of the null loop (a loop with the same number of rounds but empty loop body) is subtracted from the time of the real loop.
The null loop times are cached, the key being the number of rounds. The caching can be controlled using calls like these:
clearcache($key); clearallcache();
disablecache(); enablecache();
time
and the granularity is
therefore only one second.
Short tests may produce negative figures because perl can appear to take longer to execute the empty loop than a short test; try:
timethis(100,'1');
The system time of the null loop might be slightly more than the system time of the loop with the actual code and therefore the difference might end up being < 0.
More documentation is needed :-( especially for styles and formats.