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

Re: Does "preallocating hash improve performance"? Or "using a hash slice"?

by Marshall (Canon)
on Feb 17, 2017 at 02:03 UTC ( [id://1182184]=note: print w/replies, xml ) Need Help??


in reply to Does "preallocating hash improve performance"? Or "using a hash slice"?

I spent some effort with this idea of pre-allocation of Perl hashes. I thought it was cool and that it would do a lot. But I found out differently. In one application, I found that pre-sizing a 128K hash table made almost no significant difference at all versus letting the hash grow "naturally".

The Perl hash function has changed over the years, but the low level C implementation appears to be "solid". The Intel integer multiply has gotten faster over the years and using shifts and addition versus multiply doesn't make as much difference as it used to. Also the low level Perl mem to mem copies appear to be "fast enough" - this more apparent with bigger data sizes to be copied.

My conclusion: With less than 128K keys, don't worry about it unless there is some extreme requirement for this hash.

  • Comment on Re: Does "preallocating hash improve performance"? Or "using a hash slice"?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found