develooper Front page | perl.perl5.porters | Postings from March 2006

Re: CLONE for Tie::RefHash

Thread Previous | Thread Next
March 29, 2006 03:06
Re: CLONE for Tie::RefHash
Message ID:
On 3/29/06, Yuval Kogman <> wrote:
> On Wed, Mar 29, 2006 at 12:46:57 +0200, demerphq wrote:
> > overload::StrVal is a fairly slow procedure. Is there a reason why
> > Tie::RefHash doesnt use Scalar::Util::refaddr() instead? Its much
> > faster.
> It probably relates to it's availability, which is a non issue in
> core perl, right?
> I didn't know there was a significant difference between the two,
> but either way won't the tie interface and deep dereferencing
> overshadow the StrVal slowness?

Well i know from experience on other matters that using StrVal for
indexing reference lookups is massively slower than using refaddr. I
just whipped up a benchmark and it shows that refaddr is an order of
magnitude faster than than StrVal. And IMO if you are already dealing
with a piggish interface (ie a tied hash) then you aught to careful
about trimming unnecessary fat elsewhere.


use Benchmark qw(cmpthese);

use Scalar::Util qw(refaddr);
use overload;


my $aref=[];
my $cref=bless {},'OL';
my $href={};
my %sv;
my %ra;

cmpthese -1,{
sv => sub { $sv{StrVal($_)}++ for $aref,$cref,$href; },
ra => sub { $sv{refaddr($_)}++ for $aref,$cref,$href; },

package OL;
use overload '""'=>sub{return 1};

       Rate    sv    ra
sv  11113/s    --  -94%
ra 177337/s 1496%    --

perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About