Honourable Monks,
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.
%h = qw( ... ); $h = \%h; # Accessing the hash and the hash reference in a tight loop. for ( ... ) { my $frobnitz = $h{frobnitz}; my $quark = $h->{quark}; ... }
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.
--
print "Just Another Perl Adept\n";
In reply to Hash references versus hashes: is there a performance hit? by vrk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |