| 1 | ## | ||
| 2 | # name: Mo::Benchmarks | ||
| 3 | # abstract: Benchmarks for Moose Family Modules | ||
| 4 | # author: Ingy döt Net <ingy@cpan.org> | ||
| 5 | # license: perl | ||
| 6 | # copyright: 2011 | ||
| 7 | |||
| 8 | 1 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use Mouse 0.93 (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 0 | ▶ | use MouseX::App::Cmd 0.08 (); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | |||
| 13 | #------------------------------------------------------------------------------# | ||
| 14 | package Mo::Benchmarks; | ||
| 15 | |||
| 16 | our $VERSION = '0.10'; | ||
| 17 | |||
| 18 | #------------------------------------------------------------------------------# | ||
| 19 | package Mo::Benchmarks::Command; | ||
| 20 | use App::Cmd::Setup -command; | ||
| 21 | use Mouse; | ||
| 22 | extends 'MouseX::App::Cmd::Command'; | ||
| 23 | |||
| 24 | sub validate_args {} | ||
| 25 | |||
| 26 | # Semi-brutal hack to suppress extra options I don't care about. | ||
| 27 | around usage => sub { | ||
| 28 | my $orig = shift; | ||
| 29 | my $self = shift; | ||
| 30 | my $opts = $self->{usage}->{options}; | ||
| 31 | @$opts = grep { $_->{name} ne 'help' } @$opts; | ||
| 32 | return $self->$orig(@_); | ||
| 33 | }; | ||
| 34 | |||
| 35 | #-----------------------------------------------------------------------------# | ||
| 36 | package Mo::Benchmarks; | ||
| 37 | use App::Cmd::Setup -app; | ||
| 38 | use Mouse; | ||
| 39 | extends 'MouseX::App::Cmd'; | ||
| 40 | |||
| 41 | use Module::Pluggable | ||
| 42 | require => 1, | ||
| 43 | search_path => [ 'Mo::Benchmarks::Command' ]; | ||
| 44 | Mo::Benchmarks->plugins; | ||
| 45 | |||
| 46 | #------------------------------------------------------------------------------# | ||
| 47 | package Mo::Benchmarks::Command::constructor; | ||
| 48 | Mo::Benchmarks->import( -command ); | ||
| 49 | use Mouse; | ||
| 50 | extends 'Mo::Benchmarks::Command'; | ||
| 51 | |||
| 52 | use Benchmark ':all'; | ||
| 53 | |||
| 54 | use constant abstract => 'Run constructor benchmarks'; | ||
| 55 | use constant usage_desc => | ||
| 56 | 'mo-benchmarks constructor --count=1000000 Moose Mouse Moo Mo'; | ||
| 57 | |||
| 58 | has count => ( | ||
| 59 | is => 'ro', | ||
| 60 | isa => 'Num', | ||
| 61 | documentation => 'Number of times to run a test', | ||
| 62 | ); | ||
| 63 | |||
| 64 | sub execute { | ||
| 65 | my ($self, $opt, $args) = @_; | ||
| 66 | my @mo = map lc, grep !/^--/, @$args; | ||
| 67 | @mo = qw'mo moo mouse moose' unless @mo; | ||
| 68 | my $tests = { | ||
| 69 | map { | ||
| 70 | my $t = $_; | ||
| 71 | my $l = lc($t); | ||
| 72 | my $m = | ||
| 73 | eval <<"..."; | ||
| 74 | package $l; | ||
| 75 | use $t; | ||
| 76 | has good => (is => 'ro'); | ||
| 77 | has bad => (is => 'ro'); | ||
| 78 | has ugly => (is => 'rw'); | ||
| 79 | $l->new(good => 'Perl', bad => 'Python', ugly => 'Ruby'); | ||
| 80 | ... | ||
| 81 | my $v = do { no strict 'refs'; ${$t."::VERSION"} }; | ||
| 82 | ($l => [ "$t $v" => | ||
| 83 | sub { | ||
| 84 | # my $m = | ||
| 85 | $l->new(good => 'Perl', bad => 'Python', ugly => 'Ruby'); | ||
| 86 | # $m->good; | ||
| 87 | # $m->bad; | ||
| 88 | # $m->ugly; | ||
| 89 | # $m->ugly('Bunny'); | ||
| 90 | } | ||
| 91 | ]) | ||
| 92 | } qw(Mo Moo Mouse Moose) | ||
| 93 | }; | ||
| 94 | |||
| 95 | my $count = $self->count || 1000; | ||
| 96 | my $num = 1; | ||
| 97 | timethese($count, { | ||
| 98 | map { | ||
| 99 | ( | ||
| 100 | $num++ . ") $_->[0]", | ||
| 101 | $_->[1] | ||
| 102 | ) | ||
| 103 | } map $tests->{$_}, @mo | ||
| 104 | }); | ||
| 105 | } | ||
| 106 | |||
| 107 | #------------------------------------------------------------------------------# | ||
| 108 | package Mo::Benchmarks::Command; | ||
| 109 | |||
| 110 | # Common subroutines: | ||
| 111 | |||
| 112 | 1; | ||
| 113 | |||
| 114 | =head1 SYNOPSIS | ||
| 115 | |||
| 116 | ... | ||
| 117 | |||
| 118 | =head1 DESCRIPTION | ||
| 119 | |||
| 120 | ... | ||