Skip to content

Instantly share code, notes, and snippets.

@schwern
Created September 27, 2012 19:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schwern/3795945 to your computer and use it in GitHub Desktop.
Save schwern/3795945 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
cmpthese shift || -3, {
"shift" => sub {
my $arg = shift;
},
"array" => sub {
my($arg) = @_;
},
"1 element scalar" => sub {
my $arg = $_[0];
},
"1 element list" => sub {
my($arg) = $_[0];
},
};
__DATA__
NOTE: This is benchmarking a subroutine being passed NO arguments.
It could all change if it were passed arguments.
Also these numbers are fairly volatile, changing as much as 20% between runs.
Not surprising as we're benchmarking such a fast operation.
5.10.1 no threads
Rate array 1 element list shift 1 element scalar
array 11904762/s -- -15% -35% -48%
1 element list 13986014/s 17% -- -23% -39%
shift 18181818/s 53% 30% -- -21%
1 element scalar 22988506/s 93% 64% 26% --
5.12.4 with threads
Rate array 1 element list shift 1 element scalar
array 11764706/s -- -5% -28% -45%
1 element list 12422360/s 6% -- -24% -42%
shift 16260163/s 38% 31% -- -24%
1 element scalar 21276596/s 81% 71% 31% --
5.14.1 with threads
Rate array 1 element list shift 1 element scalar
array 9433962/s -- -17% -36% -49%
1 element list 11363636/s 20% -- -23% -38%
shift 14705882/s 56% 29% -- -20%
1 element scalar 18348624/s 94% 61% 25% --
5.16.1 no threads
Rate array 1 element list 1 element scalar shift
array 10638298/s -- -13% -56% -61%
1 element list 12195122/s 15% -- -49% -55%
1 element scalar 24096386/s 127% 98% -- -11%
shift 27027027/s 154% 122% 12% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment