Skip to content

Instantly share code, notes, and snippets.

@aero
Created September 15, 2011 02:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aero/1218367 to your computer and use it in GitHub Desktop.
Save aero/1218367 to your computer and use it in GitHub Desktop.
Moose vs Mouse vs Moo vs Mo
* 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)
Copy link

ghost commented Apr 20, 2013

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) ^_^ !!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment