Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Hash reference searching

by JadeNB (Chaplain)
on Dec 07, 2009 at 17:25 UTC ( #811567=note: print w/replies, xml ) Need Help??


in reply to Hash reference searching

I find your hashref-checking code quite strange—you are de-referencing (%{$HASH_REF}) a hashref ($HASH_REF), then treating the de-reference as a hash-ref itself ({%{$HASH_REF}}->{$random_number})—which I wouldn't expect to run at all. (UPDATE: kyle explained what I was too sleepy to notice—the extra pair of braces is re-creating a hashref from the de-referenced hashref, and you're then de-referencing it again before checking for existence.) Anyway, it does run, and I also observe a significant slow-down in the second loop, whatever it's doing.

Since I don't know what the second loop is doing, there could be lots of reasons, but one obvious candidate is that indirection has a cost, and all that de-referencing doesn't come for free. Changing the second loop to

my %HASH_DEREF = %$HASH_REF; for(...){ my $random_number = ...; 1 if exists $HASH_DEREF{$random_number}; }
gives a running time nearly identical to the first.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2021-05-15 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (151 votes). Check out past polls.

    Notices?