Benchmarks for Class::Method::Modifiers and Class::Method::Modifiers::Fast
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
use v5.14; | |
use Benchmark ':all'; | |
use Test::More; | |
package Base { | |
no thanks; | |
sub new { bless \@_, shift } | |
sub foo { 1 }; | |
sub bench { | |
my $class = shift; | |
for my $x (0 .. 100) { | |
my $obj = $class->new($x); | |
$obj->foo for 0 .. 10; | |
} | |
}; | |
} | |
package CMM { | |
use base qw(Base); | |
use Class::Method::Modifiers; | |
around foo => sub { my $orig = shift; my $self = shift; $self->$orig(@_) + 1 }; | |
} | |
package CMMF { | |
use base qw(Base); | |
use Class::Method::Modifiers::Fast; | |
around foo => sub { my $orig = shift; my $self = shift; $self->$orig(@_) + 1 }; | |
} | |
diag sprintf("Testing Perl %s", $]); | |
diag sprintf("Testing CMM %s", 'Class::Method::Modifiers'->VERSION); | |
diag sprintf("Testing CMMF %s", 'Class::Method::Modifiers::Fast'->VERSION); | |
for my $class (qw/ CMM CMMF /) | |
{ | |
is($class->new->foo, 2, "$class works"); | |
my $bench = timethis(-3, sub { $class->bench }, undef, 'none'); | |
diag sprintf("%s iterations: %d", $_, $bench->[5]); | |
} | |
done_testing(); | |
__END__ | |
# Testing Perl 5.016000 | |
# Testing CMM 1.12 | |
# Testing CMMF 0.041 | |
ok 1 - CMM works | |
# iterations: 305 | |
ok 2 - CMMF works | |
# iterations: 262 | |
1..2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment