Created
October 24, 2010 09:22
-
-
Save melo/643371 to your computer and use it in GitHub Desktop.
A benchmark comparing Method::Signatures with hand-written sub's
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 'cmpthese'; | |
use Method::Signatures ':DEBUG'; | |
sub sub_empty { } | |
func func_empty {} | |
sub sub_empty_method { my $self = shift; } | |
method meth_empty_method {} | |
sub sub_one_arg_method { | |
my ($self, $xpto) = @_; | |
die unless $xpto == 42; | |
} | |
sub sub_one_arg_method_opt { | |
my $self = shift; | |
my $xpto = $_[0]; | |
die unless $xpto == 42; | |
} | |
method meth_one_arg_method_opt ($xpto?) { die unless $xpto == 42 } | |
method meth_one_arg_method ($xpto) { die unless $xpto == 42 } | |
cmpthese( | |
-2, | |
{ 'sub_empty' => sub { sub_empty() }, | |
'func_empty' => sub { func_empty() }, | |
'sub_empty_method' => sub { main->sub_empty_method() }, | |
'meth_empty_method' => sub { main->meth_empty_method() }, | |
'sub_one_arg_method' => sub { main->sub_one_arg_method(42) }, | |
'sub_one_arg_method_opt' => sub { main->sub_one_arg_method_opt(42) }, | |
'meth_one_arg_method' => sub { main->meth_one_arg_method(42) }, | |
'meth_one_arg_method_opt' => sub { main->meth_one_arg_method(42) }, | |
} | |
); |
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
Rate meth_one_arg_method meth_one_arg_method_opt sub_one_arg_method sub_one_arg_method_alt | |
meth_one_arg_method 868844/s -- -0% -11% -13% | |
meth_one_arg_method_opt 869668/s 0% -- -10% -13% | |
sub_one_arg_method 971667/s 12% 12% -- -3% | |
sub_one_arg_method_opt 998731/s 15% 15% 3% -- |
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
Rate meth_one_arg_method_opt meth_one_arg_method sub_one_arg_method sub_one_arg_method_alt sub_empty_method meth_empty_method func_empty sub_empty | |
meth_one_arg_method_opt 873809/s -- -0% -10% -12% -40% -40% -68% -68% | |
meth_one_arg_method 873810/s 0% -- -10% -12% -40% -40% -68% -68% | |
sub_one_arg_method 971667/s 11% 11% -- -2% -33% -33% -65% -65% | |
sub_one_arg_method_opt 990720/s 13% 13% 2% -- -32% -32% -64% -64% | |
sub_empty_method 1457542/s 67% 67% 50% 47% -- -0% -47% -47% | |
meth_empty_method 1459662/s 67% 67% 50% 47% 0% -- -47% -47% | |
func_empty 2752511/s 215% 215% 183% 178% 89% 89% -- -0% |
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
DEBUG: import for main done | |
DEBUG: inject: | |
DEBUG: inject: my $self = shift; | |
DEBUG: proto: $xpto? | |
DEBUG: sig: $VAR1 = { | |
'proto' => '$xpto?', | |
'name' => 'xpto', | |
'is_ref_alias' => '', | |
'is_slurpy' => '', | |
'sigil' => '$', | |
'is_optional' => 1, | |
'named' => '', | |
'var' => '$xpto', | |
'is_at_underscore' => '', | |
'idx' => 0 | |
}; | |
DEBUG: inject: my $self = shift; my $xpto = $_[0]; | |
DEBUG: proto: $xpto | |
DEBUG: sig: $VAR1 = { | |
'proto' => '$xpto', | |
'name' => 'xpto', | |
'is_ref_alias' => '', | |
'is_slurpy' => '', | |
'sigil' => '$', | |
'is_optional' => '', | |
'named' => '', | |
'var' => '$xpto', | |
'is_at_underscore' => '', | |
'idx' => 0 | |
}; | |
DEBUG: inject: my $self = shift; Method::Signatures::required_arg('$xpto') unless (@_ > 0); my $xpto = $_[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment