Created
July 13, 2013 21:38
-
-
Save Stantheman/5992323 to your computer and use it in GitHub Desktop.
comparing typeglob aliases to references
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ ~ 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