in reply to Re: Ref to hash entries are faster?
in thread Ref to hash entries are faster?

This is the real answer. 46% faster. 200 nanos is 200 more than 0.

I am doing some network monitoring on a 100Mb network. Sharing CPU with the real application (customer too cheap for a dedicated monitoring box). At least 2 threads locking either the total hash, or an element of the hash. I have to minimize the lockout periods to maximize the chance of keeping up with the data stream.

Also learned about the benchmark module. Thanks

As to the spelling, This is modified code; I hadn't tried the reference to element itself, just winged it for the question.

Thanks to all....

Replies are listed 'Best First'.
Re^3: Ref to hash entries are faster?
by Not_a_Number (Prior) on Nov 29, 2006 at 23:16 UTC

    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% --