Created
September 15, 2011 02:27
-
-
Save aero/1218367 to your computer and use it in GitHub Desktop.
Moose vs Mouse vs Moo vs Mo
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
* Bo.pm | |
package Bo; | |
sub new { | |
my ($class) = @_; | |
return bless { buff => 0 }, $class; | |
} | |
sub buff { | |
my ($self, $var) = @_; | |
if (defined $var) { | |
$self->{buff} = $var; | |
} | |
return $self->{buff}; | |
} | |
1; | |
* Boo.pm | |
package Boo; | |
use Mo; | |
#use Moo; | |
#use Mouse; | |
#use Moose; | |
has 'buff' => (is => 'rw'); | |
#__PACKAGE__->meta->make_immutable(); | |
1; | |
* Moose | |
$ perl -MBenchmark -E 'use Boo;use Bo;timethese(100000,{Boo=>sub{my $o=Boo->new}, Bo=>sub{my $o=Bo->new}})' | |
Benchmark: timing 100000 iterations of Bo, Boo... | |
Bo: 0 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 833333.33/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
Boo: 0 wallclock secs ( 0.40 usr + 0.00 sys = 0.40 CPU) @ 250000.00/s (n=100000) | |
$ perl -MBenchmark -E 'use Boo;use Bo;my $o=Boo->new;my $o2=Bo->new;timethese(100000,{Boo=>sub{$o->buff(5);$o->buff}, Bo=>sub{$o2->buff(5);$o2->buff}})' | |
Benchmark: timing 100000 iterations of Bo, Boo... | |
Bo: 0 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 833333.33/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
Boo: 0 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU) @ 1111111.11/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
* Mouse | |
$ perl -MBenchmark -E 'use Boo;use Bo;timethese(100000,{Boo=>sub{my $o=Boo->new}, Bo=>sub{my $o=Bo->new}})' | |
Benchmark: timing 100000 iterations of Bo, Boo... | |
Bo: 0 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 833333.33/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
Boo: 0 wallclock secs ( 0.10 usr + 0.00 sys = 0.10 CPU) @ 1000000.00/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
$ perl -MBenchmark -E 'use Boo;use Bo;my $o=Boo->new;my $o2=Bo->new;timethese(100000,{Boo=>sub{$o->buff(5);$o->buff}, Bo=>sub{$o2->buff(5);$o2->buff}})' | |
Benchmark: timing 100000 iterations of Bo, Boo... | |
Bo: 0 wallclock secs ( 0.15 usr + 0.00 sys = 0.15 CPU) @ 666666.67/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
Boo: 0 wallclock secs ( 0.04 usr + 0.00 sys = 0.04 CPU) @ 2500000.00/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
* Moo | |
$ perl -MBenchmark -E 'use Boo;use Bo;timethese(100000,{Boo=>sub{my $o=Boo->new}, Bo=>sub{my $o=Bo->new}})' | |
Benchmark: timing 100000 iterations of Bo, Boo... | |
Bo: 1 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 833333.33/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
Boo: 0 wallclock secs ( 0.19 usr + 0.00 sys = 0.19 CPU) @ 526315.79/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
$ perl -MBenchmark -E 'use Boo;use Bo;my $o=Boo->new;my $o2=Bo->new;timethese(100000,{Boo=>sub{$o->buff(5);$o->buff}, Bo=>sub{$o2->buff(5);$o2->buff}})' | |
Benchmark: timing 100000 iterations of Bo, Boo... | |
Bo: 0 wallclock secs ( 0.15 usr + 0.00 sys = 0.15 CPU) @ 666666.67/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
Boo: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU) @ 3333333.33/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
* Mo | |
$ perl -MBenchmark -E 'use Boo;use Bo;timethese(100000,{Boo=>sub{my $o=Boo->new}, Bo=>sub{my $o=Bo->new}})' | |
Benchmark: timing 100000 iterations of Bo, Boo... | |
Bo: 0 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 833333.33/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
Boo: 1 wallclock secs ( 0.42 usr + 0.00 sys = 0.42 CPU) @ 238095.24/s (n=100000) | |
$ perl -MBenchmark -E 'use Boo;use Bo;my $o=Boo->new;my $o2=Bo->new;timethese(100000,{Boo=>sub{$o->buff(5);$o->buff}, Bo=>sub{$o2->buff(5);$o2->buff}})' | |
Benchmark: timing 100000 iterations of Bo, Boo... | |
Bo: 0 wallclock secs ( 0.15 usr + 0.00 sys = 0.15 CPU) @ 666666.67/s (n=100000) | |
(warning: too few iterations for a reliable count) | |
Boo: 0 wallclock secs ( 0.10 usr + 0.00 sys = 0.10 CPU) @ 1000000.00/s (n=100000) | |
(warning: too few iterations for a reliable count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when i use moose to test, the Boo module performance:
Boo: 19 wallclock secs (18.01 usr + 0.00 sys = 18.01 CPU) @ 5552.47/s (n=100000) ^_^ !!!!!