Hash references versus hashes: is there a performance hit?by w-ber (Hermit)
|on Mar 06, 2007 at 20:07 UTC||Need Help??|
w-ber has asked for the
wisdom of the Perl Monks concerning the following question:
I often ponder the performance of the code I am writing, but I do this at a relatively high, algorithmical level. I rarely dig into the intricate world of instructions (be it machine language or Perl bytecode). Recently a question has been forming in my mind: is there a performance hit if you use hash references instead of hashes? Allow me to elaborate.
Is the latter hash access slower than the former, and if so, how much? Does either consume more memory than the other? Should I be aware of other possible overhead? If I have a complex data structure (HoHoHo...), would I be able to squeeze off some performance from using real hashes instead of hash references?
This is not a burning question, because I very rarely write code in Perl where I would need to mind these things. However, I'm curious.
I know I could possibly test this myself with a profiler, but I have yet to read how to use the Perl profiler, or even to figure out which would be a good test scenario.
Thank you for your patience.