Skip Menu |

This queue is for tickets about the File-Path CPAN distribution.

Report information
The Basics
Id: 40807
Status: rejected
Worked: 10 min
Priority: 0/
Queue: File-Path

People
Owner: dland [...] cpan.org
Requestors: dmuey [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: UNIVERSAL::isa() for reference type discovery is slow
Hello, Just a little something I noticed that might help a bit When trying to discover a reference's type, instead of this UNIVERSAL::isa($x, 'HASH') do this: ref $x eq 'HASH' It's over twice as fast checking vars that are references and almost 3 times when checking vars that are not references: Rate isa ref isa nr ref nr isa 3521127/s -- -54% -60% -74% ref 7692308/s 118% -- -12% -44% isa nr 8771930/s 149% 14% -- -36% ref nr 13698630/s 289% 78% 56% --
Subject: isa_eq.pl
#!/usr/bin/perl use Benchmark; my $hr = {}; my $nr; Benchmark::cmpthese(10_000_000, { 'ref' => sub { if(ref $hr eq 'HASH') {} }, 'isa' => sub { if(UNIVERSAL::isa($hr, 'HASH')) {} }, 'ref nr' => sub { if(ref $nr eq 'HASH') {} }, 'isa nr' => sub { if(UNIVERSAL::isa($nr, 'HASH')) {} }, });
On Mon Nov 10 08:51:05 2008, DMUEY wrote: Show quoted text
> Hello, > > Just a little something I noticed that might help a bit > > When trying to discover a reference's type, instead of this > UNIVERSAL::isa($x, 'HASH') > do this: > ref $x eq 'HASH'
You're look at this the wrong way. The results of your benchmark suggest that this will be a problem if rmtree() or mkpath() is called more than 4 million times a second. That is unlikely to occur. Furthermore, once you start doing system calls which trigger IO, any remaining difference will quickly be lost in the noise. What the isa() construct does buy you is the ability to use hash refs that have been blessed into other packages, such as when using mixins. This is is much more likely to happen. Thanks for taking the time to write, David Landgren
Show quoted text
> What the isa() construct does buy you is the ability to use hash refs > that have been blessed into other packages, such as when using mixins. > This is is much more likely to happen.
Good point, well worth a very tiny speed advantage, thanks for that Show quoted text
> Thanks for taking the time to write, > David Landgren
no no, thank you