A nulltime compensation is effective when the overhead is relatively small compared to the sentence execution time. But when it is much bigger as in this case, the compensated overhead (aka error) can still be of the same order of magnitude of the time we want to measure.
Guess why the last line you have quoted from the source is there!
package DB; use Time::HiRes; my %testDB = ( null => sub { my($pkg,$filename,$line) = caller; $profile || return; %packages && !$packages{$pkg} && return; }, work => sub { $do_something{foo} = 'bar'; my($pkg,$filename,$line) = caller; $profile || return; %packages && !$packages{$pkg} && return; }); my $n = 10; for (1..$n) { for my $t (keys %testDB) { my $testDB = $testDB{$t}; my $nulltime = 0; for (1..100) { my($u,$s,$cu,$cs) = times; $cstart = $u+$s+$cu+$cs; $start = Time::HiRes::time; &$testDB; ($u,$s,$cu,$cs) = times; $cdone = $u+$s+$cu+$cs; $done = Time::HiRes::time; $diff = $done - $start; $nulltime += $diff; } $time{$t} = $nulltime / 100 * 1e6; } printf "null: %.2f, work: %.2f, delta: %.2f\n", $time{null}, $time{work}, $time{work} - $time{null}; }
In reply to Re^8: "Automated" benchmarking
by salva
in thread "Automated" benchmarking
by DreamT
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |