Skip to content

Instantly share code, notes, and snippets.

@Stantheman
Created June 14, 2013 17:19
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/5783686 to your computer and use it in GitHub Desktop.
Save Stantheman/5783686 to your computer and use it in GitHub Desktop.
#!/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;
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