Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Effecicncy of key-only hash

by ysth (Canon)
on Aug 24, 2008 at 18:01 UTC ( [id://706574]=note: print w/replies, xml ) Need Help??


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

undef(@hash{qw(shave the modern way)});
Do @hash{qw(shave the modern way)}=(); instead. It's arguably a bug that the former creates the shave, the, and modern keys if they don't exist. Note that it does not set their values to undef if they do already exist.

Replies are listed 'Best First'.
Re^3: Effecicncy of key-only hash
by tilly (Archbishop) on Aug 24, 2008 at 22:35 UTC
    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. :-)

        AFAIK, a hash slice is considered an array and not a list... that's why it begins with '@' :-)
        []s, HTH, Massa (κς,πμ,πλ)
      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://706574]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-24 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found