Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
MooseX::Method::Signatures vs Method::Signatures vs PurePerl
{
package WithMXMS;
use Moose;
use MooseX::Method::Signatures;
method gndn {}
}
{
package WithMXMS_immutable;
use Moose;
use MooseX::Method::Signatures;
method gndn {}
__PACKAGE__->meta->make_immutable;
}
{
package PurePerl;
sub new { bless {}, shift };
sub gndn {}
# To match what MXMS and MS do
sub gndn_with_shift { my $self = shift; }
}
# Demonstrating that MS is being affected by a Perl performance issue
# with aliased function calls.
{
package PurePerl_alias;
sub new { bless {}, shift };
*gndn = sub {};
# To match what MXMS and MS do
*gndn_with_shift = sub { my $self = shift; };
}
{
package MS_method;
use Method::Signatures;
sub new { bless {}, shift };
method gndn {}
# Disable all argument checks
method gndn_no_check (@_) {}
}
{
package MS_func;
use Method::Signatures;
func gndn {}
# Disable all argument checks
func gndn_no_check (@_) {}
}
use v5.14;
use Time::HiRes qw(time);
my $Runs = 15_000;
say "Running $Runs empty method calls each";
{
my $obj = WithMXMS->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for MooseX::Method::Signatures method call";
}
{
my $obj = WithMXMS_immutable->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for MooseX::Method::Signatures method call (immutable)";
}
{
my $obj = PurePerl->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl method call";
}
{
my $obj = PurePerl->new;
my $start = time;
$obj->gndn_with_shift for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl method call with 'my \$self = shift'";
}
{
my $start = time;
PurePerl::gndn() for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl function call";
}
{
my $obj = PurePerl_alias->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl aliased method call";
}
{
my $obj = PurePerl_alias->new;
my $start = time;
$obj->gndn_with_shift for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl aliased method call with 'my \$self = shift'";
}
{
my $start = time;
PurePerl_alias::gndn() for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Pure Perl aliased function call";
}
{
my $obj = MS_method->new;
my $start = time;
$obj->gndn for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Method::Signatures method call";
}
{
my $obj = MS_method->new;
my $start = time;
$obj->gndn_no_check for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Method::Signatures method call with no arg checks";
}
{
my $start = time;
MS_func::gndn() for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Method::Signatures func call";
}
{
my $start = time;
MS_func::gndn_no_check() for 1..$Runs;
my $end = time;
say +($end - $start)." seconds for Method::Signatures func call with no arg checks";
}
__END__
(Results with Perl 5.14.1 on Macbook i7/2.7Ghz)
(Method::Signatures 20110923.1726)
(MooseX::Method::Signatures 0.37)
Running 15000 empty method calls each
1.07040405273438 seconds for MooseX::Method::Signatures method call
1.06590795516968 seconds for MooseX::Method::Signatures method call (immutable)
0.00235891342163086 seconds for Pure Perl method call
0.00326395034790039 seconds for Pure Perl method call with 'my $self = shift'
0.00190520286560059 seconds for Pure Perl function call
0.00234508514404297 seconds for Pure Perl aliased method call
0.0032198429107666 seconds for Pure Perl aliased method call with 'my $self = shift'
0.00182890892028809 seconds for Pure Perl aliased function call
0.00393080711364746 seconds for Method::Signatures method call
0.00322699546813965 seconds for Method::Signatures method call with no arg checks
0.00242090225219727 seconds for Method::Signatures func call
0.00255417823791504 seconds for Method::Signatures func call with no arg checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.