Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Effecicncy of key-only hash

by tilly (Archbishop)
on Aug 24, 2008 at 22:35 UTC ( [id://706595]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Effecicncy of key-only hash
in thread Effecicncy of key-only hash

Many years ago there was a discussion on p5p about the fastest way to initialize an empty hash. I forget who it was who brought up that construct as the fastest possible way to do it, but I do remember it was someone who should know. Maybe Nick Ing-Simmons, but I won't swear to it. However at the time it was certainly faster than assigning an empty list because all other versions created temporary intermediate scalars and that one does not.

Of course now, many versions later, it might not be still true. But that fragment has stuck in my head.

Please note that I included that version for amusement, and not for serious use. Which I indicated with my comment about the maintenance programmer's response. Which comment has been confirmed by the questions and complaints we've had. :-)

Replies are listed 'Best First'.
Re^4: Effecicncy of key-only hash
by ysth (Canon) on Aug 24, 2008 at 23:28 UTC
      AFAIK, a hash slice is considered an array and not a list... that's why it begins with '@' :-)
      []s, HTH, Massa (κς,πμ,πλ)
        perldata:
        If you’re confused about why you use an ’@’ there on a hash slice instead of a ’%’, think of it like this. The type of bracket (square or curly) governs whether it’s an array or a hash being looked at. On the other hand, the leading symbol (’$’ or ’@’) on the array or hash indicates whether you are getting back a singular value (a scalar) or a plural one (a list).
Re^4: Effecicncy of key-only hash
by brycen (Monk) on Aug 25, 2008 at 06:26 UTC
    Since I'm in mod_perl I don't care at all how fast the hash initializes. I only care about the memory footprint, and to a lesser extent the lookup time.
      Then (according to all benchmarks here) you should go with undefining the hash slice (undef @h{qw{a b c d}}).
      []s, HTH, Massa (κς,πμ,πλ)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-28 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found