Skip to content

Instantly share code, notes, and snippets.

@gfx
Created December 22, 2009 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfx/261549 to your computer and use it in GitHub Desktop.
Save gfx/261549 to your computer and use it in GitHub Desktop.
#!perl -w
# $ perl -Mblib benchmark-reftype.pl
# $ perl benchmark-reftype.pl
use strict;
use Benchmark qw(:all);
use Scalar::Util;
my $ref = {};
cmpthese timethese -1 => {
reftype => sub{ my $x = Scalar::Util::reftype($ref) for 1 .. 100 },
ref => sub{ my $x = ref $ref for 1 .. 100 },
};
$ perl -Mblib benchmark-reftype.pl # patched
Perl/5.10.0 on i686-linux-thread-multi, Scalar::Util/1.21
Benchmark: running ref, reftype for at least 1 CPU seconds...
ref: 1 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 26795.33/s (n=28671)
reftype: 1 wallclock secs ( 1.03 usr + 0.00 sys = 1.03 CPU) @ 16059.22/s (n=16541)
Rate reftype ref
reftype 16059/s -- -40%
ref 26795/s 67% --
$ perl - benchmark-reftype.pl # on CPAN
Perl/5.10.0 on i686-linux-thread-multi, Scalar::Util/1.22
Benchmark: running ref, reftype for at least 1 CPU seconds...
ref: 1 wallclock secs ( 1.14 usr + 0.01 sys = 1.15 CPU) @ 26713.04/s (n=30720)
reftype: 1 wallclock secs ( 1.09 usr + 0.00 sys = 1.09 CPU) @ 14090.83/s (n=15359)
Rate reftype ref
reftype 14091/s -- -47%
ref 26713/s 90% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment