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

Re: CLONE for Tie::RefHash

Thread Previous | Thread Next
From:
demerphq
Date:
March 29, 2006 03:06
Subject:
Re: CLONE for Tie::RefHash
Message ID:
9b18b3110603290305l58699a97sdaeba89809c2f4ee@mail.gmail.com
On 3/29/06, Yuval Kogman <nothingmuch@woobling.org> 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.

Yves

use Benchmark qw(cmpthese);

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

*StrVal=*overload::StrVal;

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};

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


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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About