This is completely OT as far as this thread is concerned, and is totally meaningless (probably) anyway, but I'd dearly like an explaination anyway.
Reading tachyon's modified benchmark it struck me that if purely the load time was of interest, then the simple expedient of deleting a non-existant hash key probably didn't quite cut it when it came to removing the "administrative overhead" of use from the equation, so I modified it slightly to create and delete a key each time to see the effect that had.
The results are surprising, and somewhat confusing.
Pre-tye code
The biggy!! Post-tye correction.
use Benchmark 'cmpthese';
my %hash = ( key => 'value' );
cmpthese( -3, {
with => sub {
delete $INC{'strict.pm'};
require 'strict.pm';
strict::import( 'refs' );
my $a = 1;
my $b = 2
},
without => sub {
$hash{key} = delete $hash{key};
my $a = 1; my $b = 2
},
} );
__END__
P:\test>..\bin\perl.exe junk.pl8
Rate with without
with 137/s -- -99%
without 24226/s 17576% --
Which apart from the fact that tachyon's machine is about 20x quicker than mine, is a mildly interesting result. However, I'm not sure that I'm really comparing eggs with eggs, so I had another go.
This time, I thought I would force Benchmark to re-compile (eval) both snippets each time it exercised them, rather than just call a pre-compiled sub and I got these results.
Pre-tye code
Post-tye corrected benchmark use Benchmark 'cmpthese';
my %hash = ( key => 'value' );
cmpthese( -10, {
with => q[
BEGIN{ delete $INC{'strict.pm'}; use strict 'refs' }
my $a = 1; my $b = 2
],
without => q[
BEGIN{ $hash{'key'} = delete $hash{key} }
my $a = 1; my $b = 2
],
} );
__END__
P:\test>..\bin\perl.exe junk.pl8
Rate with without
with 368780/s -- -2%
without 375558/s 2% --
P:\test>..\bin\perl.exe junk.pl8
Rate with without
with 371638/s -- -1%
without 374367/s 1% --
Which, without drawing any conclusions as I am still not particularly certain that I am really comparing eggs with eggs, is much closer to my real world experience of benchmarking complete programs with and without use strict.
Whenever I tried this before, I nearly always found that the differences were marginal, if detectable.
Did any of my attempts get closer to a real world test?
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
|