gam3 has asked for the wisdom of the Perl Monks concerning the following question:
Once not that long ago someone told me that
Removed unused code.
is faster thanmy $hash = { a => 'b' }; $hash->{$x}
I finally got around to testing this statment. I found that it was completely wrong. I was also suprised at the difference.{a => 'b'}->{$x}
our $hash = { 'a' => 'A', 'b' => 'B'}; our $y = 'bob'; cmpthese(-10, { 'hash' => sub { for my $x (qw(a b a b a b)) { my $y = { 'a' => 'A' +, 'b' => 'B'}->{$x}; }}, 'ref' => sub { for my $x (qw(a b a b a b)) { my $y = $hash->{$x}; +}}, });
Rate hash ref hash 11956/s -- -73% ref 43773/s 266% --Update: Well as Rosan Rosanadana used to say: Never mind!
Removed unused code.
-- gam3
A picture is worth a thousand words, but takes 200K.
A picture is worth a thousand words, but takes 200K.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to access a static hash.
by Joost (Canon) on Mar 17, 2007 at 18:16 UTC | |
by gam3 (Curate) on Mar 17, 2007 at 20:33 UTC | |
by Joost (Canon) on Mar 17, 2007 at 21:00 UTC | |
Re: How to access a static hash.
by ferreira (Chaplain) on Mar 17, 2007 at 18:19 UTC | |
Re: How to access a static hash.
by graff (Chancellor) on Mar 17, 2007 at 18:29 UTC | |
by gam3 (Curate) on Mar 18, 2007 at 16:49 UTC | |
Re: How to access a static hash.
by Sidhekin (Priest) on Mar 17, 2007 at 18:04 UTC | |
Re: How to access a static hash.
by ikegami (Patriarch) on Mar 17, 2007 at 23:13 UTC | |
Re: How to access a static hash.
by Anno (Deacon) on Mar 17, 2007 at 18:20 UTC |
Back to
Seekers of Perl Wisdom