Created
September 24, 2015 08:28
-
-
Save schwern/de54d4de0020674ce543 to your computer and use it in GitHub Desktop.
Bencharmking MooseX::Method::Signatures vs Method::Signatures vs plain Perl
This file contains 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
{ | |
package Plain; | |
use Moose; | |
sub no_args { return 42 } | |
sub one_arg { | |
my $self = shift; | |
my $arg = shift; | |
return $arg; | |
} | |
} | |
{ | |
package MS; | |
use Moose; | |
use Method::Signatures; | |
method no_args() { return 42 } | |
method one_arg($arg) { | |
return $arg; | |
} | |
} | |
{ | |
package MXMS; | |
use Moose; | |
use MooseX::Method::Signatures; | |
method no_args() { return 42 } | |
method one_arg($arg) { | |
return $arg; | |
} | |
} | |
use v5.10; | |
use strict; | |
use warnings; | |
use Benchmark qw(cmpthese); | |
my $plain = Plain->new; | |
my $ms = MS->new; | |
my $mxms = MXMS->new; | |
say "no args"; | |
cmpthese -3, { | |
plain => sub { $plain->no_args }, | |
ms => sub { $ms->no_args }, | |
mxms => sub { $mxms->no_args }, | |
}; | |
say "one arg"; | |
cmpthese -3, { | |
plain => sub { $plain->one_arg(23) }, | |
ms => sub { $ms->one_arg(23) }, | |
mxms => sub { $mxms->one_arg(23) }, | |
}; | |
__END__ | |
no args | |
Rate mms ms plain | |
mms 5694/s -- -100% -100% | |
ms 2920219/s 51186% -- -44% | |
plain 5182244/s 90912% 77% -- | |
one arg | |
Rate mms ms plain | |
mms 5729/s -- -100% -100% | |
ms 2157245/s 37553% -- -19% | |
plain 2665522/s 46425% 24% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment