in reply to Re^2: Ref to hash entries are faster?
in thread Ref to hash entries are faster?
Hmmm. Consider the following:
use strict; use warnings; use Benchmark 'cmpthese'; use constant MAX => 520; my %contracts = ( 1 .. 2 * MAX ); cmpthese ( -1, { lookup => \&lookup, refit => \&refit, } ); sub lookup { for ( keys %contracts ) { return if $contracts{$_} == MAX; } } sub refit { for ( keys %contracts ) { my $ref = \$contracts{$_}; return if $$ref == MAX; } }
Output (on my machine):
Rate refit lookup refit 4263/s -- -21% lookup 5407/s 27% --
|
|---|