Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Stantheman
Created July 13, 2013 21:38
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 Stantheman/5992323 to your computer and use it in GitHub Desktop.
Save Stantheman/5992323 to your computer and use it in GitHub Desktop.
comparing typeglob aliases to references
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw( timethese cmpthese ) ;
my $a=10;
*b = *a;
my $ref = \$a;
# getting 1 second of CPU time for incrementing is actually pretty long
my $r = timethese( -1, {
typeglob => sub {
$b++;
},
refer => sub {
$$ref++;
},
} );
cmpthese $r;
➜ ~ perl test.pl
Name "main::a" used only once: possible typo at test.pl line 8.
Benchmark: running refer, typeglob for at least 1 CPU seconds...
refer: 1 wallclock secs ( 1.46 usr + 0.01 sys = 1.47 CPU) @ 12483046.94/s (n=18350079)
typeglob: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 17476266.67/s (n=18350080)
Rate refer typeglob
refer 12483047/s -- -29%
typeglob 17476267/s 40% --
b: 22544383 ref: 22544392
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment