in reply to Re: Hashes and hash references
in thread Hashes and hash references
I like cmpthese results rather than timethese so I've reworked your benchmark a little.
The parameter passing tests were doing a lot of non-parameter passing work so I made the variables global (using our variables) and used the constructed hashes from the first two tests as the test variables for the passing tests.
Rate reference regular reference 8.00/s -- -8% regular 8.73/s 9% -- Rate regularPass referencePass regularPass 7.19/s -- -33% referencePass 10.7/s 49% --
use strict; use warnings; use Benchmark qw(cmpthese); my %hash; my $hash; cmpthese (30, {"regular" => \®ular, "reference" => \&reference}); cmpthese (30, {"regularPass" => \®ularPass, "referencePass" => \&re +ferencePass}); sub regular { our %hash; for my $i (1 .. 100000) { $hash{$i} = $i; } } sub reference { our $hash; for my $i (1 .. 100000) { $hash->{$i} = $i; } } sub regularPass { our %hash; for my $i (1 .. 100000) { helper(\%hash); } } sub referencePass { my $hash; for my $i (1 .. 100000) { helper($hash); } } sub helper { my $hash = shift; }
|
|---|