use Benchmark qw (timethese); timethese(10, {"regular" => \®ular, "reference" => \&reference}); sub regular { my %hash; for my $i (1 .. 100000) { $hash{$i} = $i; } } sub reference { my $hash; for my $i (1 .. 100000) { $hash->{$i} = $i; } } #### Benchmark: timing 10 iterations of reference, regular... reference: 8 wallclock secs ( 7.76 usr + 0.16 sys = 7.92 CPU) @ 1.26/s (n=1 0) regular: 8 wallclock secs ( 7.20 usr + 0.14 sys = 7.34 CPU) @ 1.36/s (n=1 0) Benchmark: timing 10 iterations of reference, regular... reference: 9 wallclock secs ( 7.67 usr + 0.17 sys = 7.84 CPU) @ 1.27/s (n=1 0) regular: 8 wallclock secs ( 7.23 usr + 0.08 sys = 7.31 CPU) @ 1.37/s (n=1 0) #### use Benchmark qw (timethese); timethese(10, {"regular" => \®ular, "reference" => \&reference}); sub regular { my %hash; for my $i (1 .. 100000) { $hash{$i} = $i; } helper(\%hash); } sub reference { my $hash; for my $i (1 .. 100000) { $hash->{$i} = $i; } helper($hash); } sub helper { my $hash = shift; } #### Benchmark: timing 10 iterations of reference, regular... reference: 8 wallclock secs ( 7.72 usr + 0.14 sys = 7.86 CPU) @ 1.27/s (n=1 0) regular: 9 wallclock secs ( 7.91 usr + 0.08 sys = 7.98 CPU) @ 1.25/s (n=1 0) Benchmark: timing 10 iterations of reference, regular... reference: 8 wallclock secs ( 7.70 usr + 0.11 sys = 7.81 CPU) @ 1.28/s (n=1 0) regular: 9 wallclock secs ( 7.95 usr + 0.06 sys = 8.02 CPU) @ 1.25/s (n=1 0)