in reply to Re^7: "Automated" benchmarking
in thread "Automated" benchmarking
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}; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^9: "Automated" benchmarking
by BrowserUk (Patriarch) on Jan 24, 2012 at 18:32 UTC | |
by salva (Canon) on Jan 25, 2012 at 08:26 UTC | |
by BrowserUk (Patriarch) on Jan 25, 2012 at 15:27 UTC | |
by salva (Canon) on Jan 25, 2012 at 16:32 UTC | |
by BrowserUk (Patriarch) on Jan 25, 2012 at 17:04 UTC | |
|
In Section
Seekers of Perl Wisdom