Created
June 14, 2013 17:19
-
-
Save Stantheman/5783686 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 $r = timethese( -10, { | |
val => sub { | |
my @arr; | |
push @arr, $_ for (1..10000); | |
}, | |
hash => sub { | |
my @arr; | |
push @arr, {x=>1, y=>$_} for (1..10000); | |
}, | |
} ); | |
cmpthese $r; |
This file contains hidden or 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
Benchmark: running hash, val for at least 10 CPU seconds... | |
hash: 11 wallclock secs (10.72 usr + 0.01 sys = 10.73 CPU) @ 180.15/s (n=1933) | |
val: 11 wallclock secs (10.49 usr + 0.00 sys = 10.49 CPU) @ 1152.91/s (n=12094) | |
Rate hash val | |
hash 180/s -- -84% | |
val 1153/s 540% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment