Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Ref to hash entries are faster?

by Wiggins (Hermit)
on Nov 29, 2006 at 21:28 UTC ( [id://586826]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://586826]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-16 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found