Skip to content

Instantly share code, notes, and snippets.

@stash
Created October 5, 2009 17:07
Show Gist options
  • Save stash/202249 to your computer and use it in GitHub Desktop.
Save stash/202249 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use warnings;
use strict;
use Benchmark qw/cmpthese/;
# perl 5.8.6 x86_64-linux-gnu-thread-multi
# Rate h_e l_c h_d l3_e l2_e l_e l_d l2_d l_a l2_a l2_b l_b a_c hr_e hr_f
# h_e 371747/s -- -1% -21% -22% -23% -24% -34% -40% -42% -43% -53% -53% -57% -74% -78%
# l_c 377358/s 2% -- -20% -21% -22% -23% -33% -39% -42% -42% -52% -52% -57% -73% -77%
# h_d 469484/s 26% 24% -- -2% -3% -4% -17% -24% -27% -28% -40% -40% -46% -67% -72%
# l3_e 478469/s 29% 27% 2% -- -1% -2% -15% -22% -26% -27% -39% -39% -45% -66% -71%
# l2_e 483092/s 30% 28% 3% 1% -- -1% -14% -22% -25% -26% -39% -39% -44% -66% -71%
# l_e 487805/s 31% 29% 4% 2% 1% -- -14% -21% -24% -25% -38% -38% -44% -65% -71%
# l_d 564972/s 52% 50% 20% 18% 17% 16% -- -8% -12% -14% -28% -28% -35% -60% -66%
# l2_d 617284/s 66% 64% 31% 29% 28% 27% 9% -- -4% -6% -22% -22% -29% -56% -63%
# l_a 645161/s 74% 71% 37% 35% 34% 32% 14% 5% -- -1% -18% -18% -26% -54% -61%
# l2_a 653595/s 76% 73% 39% 37% 35% 34% 16% 6% 1% -- -17% -17% -25% -54% -61%
# l2_b 787402/s 112% 109% 68% 65% 63% 61% 39% 28% 22% 20% -- -0% -9% -44% -53%
# l_b 787402/s 112% 109% 68% 65% 63% 61% 39% 28% 22% 20% 0% -- -9% -44% -53%
# a_c 869565/s 134% 130% 85% 82% 80% 78% 54% 41% 35% 33% 10% 10% -- -38% -48%
# hr_e 1408451/s 279% 273% 200% 194% 192% 189% 149% 128% 118% 115% 79% 79% 62% -- -15%
# hr_f 1666667/s 348% 342% 255% 248% 245% 242% 195% 170% 158% 155% 112% 112% 92% 18% --
# on perl 5.12.0 darwin-multi-2level (32-bit i386, core-2)
# Rate l_c h_e h_d l2_e l_e l3_e l2_a l_a l2_d l_d l_b l2_b a_c hr_e hr_f
# l_c 404858/s -- -8% -23% -36% -37% -37% -47% -48% -49% -49% -61% -62% -63% -77% -81%
# h_e 440529/s 9% -- -17% -31% -31% -32% -43% -43% -44% -45% -57% -58% -60% -75% -79%
# h_d 529101/s 31% 20% -- -17% -17% -18% -31% -32% -33% -34% -49% -50% -52% -70% -75%
# l2_e 636943/s 57% 45% 20% -- -1% -1% -17% -18% -20% -20% -38% -39% -42% -64% -69%
# l_e 641026/s 58% 46% 21% 1% -- -1% -17% -17% -19% -20% -38% -39% -42% -64% -69%
# l3_e 645161/s 59% 46% 22% 1% 1% -- -16% -17% -19% -19% -37% -39% -41% -64% -69%
# l2_a 769231/s 90% 75% 45% 21% 20% 19% -- -1% -3% -4% -25% -27% -30% -57% -63%
# l_a 775194/s 91% 76% 47% 22% 21% 20% 1% -- -2% -3% -25% -26% -29% -57% -63%
# l2_d 793651/s 96% 80% 50% 25% 24% 23% 3% 2% -- -1% -23% -25% -28% -56% -62%
# l_d 800000/s 98% 82% 51% 26% 25% 24% 4% 3% 1% -- -22% -24% -27% -55% -62%
# l_b 1030928/s 155% 134% 95% 62% 61% 60% 34% 33% 30% 29% -- -2% -6% -42% -51%
# l2_b 1052632/s 160% 139% 99% 65% 64% 63% 37% 36% 33% 32% 2% -- -4% -41% -49%
# a_c 1098901/s 171% 149% 108% 73% 71% 70% 43% 42% 38% 37% 7% 4% -- -38% -47%
# hr_e 1785714/s 341% 305% 237% 180% 179% 177% 132% 130% 125% 123% 73% 70% 62% -- -14%
# hr_f 2083333/s 415% 373% 294% 227% 225% 223% 171% 169% 162% 160% 102% 98% 90% 17% --
sub param_a {
my $a1 = shift;
my $a2 = shift;
my $a3 = shift;
my $a4 = shift;
my $a5 = shift;
my $a6 = shift;
return;
}
sub param_b {
my ($a1,$a2,$a3,$a4,$a5,$a6) = @_;
return;
}
sub param_c {
my ($a1,$a2,$a3,$a4,$a5,$a6) = @{$_[0]};
return;
}
sub param_d {
my %p = @_;
return;
}
sub param_e {
my $p = (@_==1) ? $_[0] : {@_};
return;
}
sub param_f {
my $p = shift;
return;
}
our @list_params = (steve => 1, carl => 2, bob => 3);
our %hash_params = (@list_params);
our $hashref_params = {@list_params};
our $arrayref_params = [@list_params];
cmpthese(1_000_000, {
'l_a' => sub { param_a(@list_params) },
'l2_a' => sub { param_a(steve => 1, carl => 2, bob => 3) },
'l_b' => sub { param_b(@list_params) },
'l2_b' => sub { param_b(steve => 1, carl => 2, bob => 3) },
'l_c' => sub { param_c([@list_params]) },
'a_c' => sub { param_c($arrayref_params) },
'l_d' => sub { param_d(@list_params) },
'l2_d' => sub { param_d(steve => 1, carl => 2, bob => 3) },
'h_d' => sub { param_d(%hash_params) },
'l_e' => sub { param_e(@list_params) },
'l2_e' => sub { param_e(steve => 1, carl => 2, bob => 3) },
'l3_e' => sub { param_e({@list_params}) },
'h_e' => sub { param_e(%hash_params) },
'hr_e' => sub { param_e($hashref_params) },
'hr_f' => sub { param_f($hashref_params) },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment