The performance of the blessed hash case is dependent on the length of the keys used in the hash: The longer the key, the more time it takes!
You're right, but this isn't the reason that using $self is so much slower. Stringification of references is just slow:
#! /usr/bin/perl
use strict;
use warnings;
use Benchmark qw( cmpthese );
my $self = bless {}, 'SomeClass';
my $string = "$self";
my %a = ( $self => 0 );
my %b = ( $string => 0 );
cmpthese(-1, {
self => sub { $a{ $self } = $a{ $self } + 1 },
string => sub { $b{ $string } = $b{ $string } + 1 },
});
__END__
# on my perl 5.8.7
Rate self string
self 156393/s -- -83%
string 927942/s 493% --
On another minor note, 0+$self yields the same result as the refaddr function.
Unless you overload arithmetic.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|