Skip to content

Instantly share code, notes, and snippets.

@tobyink
Last active December 16, 2015 04:49
Show Gist options
  • Select an option

  • Save tobyink/5379823 to your computer and use it in GitHub Desktop.

Select an option

Save tobyink/5379823 to your computer and use it in GitHub Desktop.
use v5.14;
use Benchmark qw(cmpthese);
{
package Antlers;
use Moose;
has a => (is => "rw");
__PACKAGE__->meta->make_immutable;
our $o = __PACKAGE__->new(a => 1);
}
{
package Horns;
use Moo;
has a => (is => "rw");
__PACKAGE__->meta->make_immutable;
our $o = __PACKAGE__->new(a => 1);
}
{
package BigEars;
use Mouse;
has a => (is => "rw");
__PACKAGE__->meta->make_immutable;
our $o = __PACKAGE__->new(a => 1);
}
say "Benchmark reading...";
cmpthese(-2, {
Moose => q[ $Antlers::o->a for 1 .. 10_000 ],
Moo => q[ $Horns::o->a for 1 .. 10_000 ],
Mouse => q[ $BigEars::o->a for 1 .. 10_000 ],
});
say "--------";
say "Benchmark writing...";
cmpthese(-2, {
Moose => q[ $Antlers::o->a($_) for 1 .. 10_000 ],
Moo => q[ $Horns::o->a($_) for 1 .. 10_000 ],
Mouse => q[ $BigEars::o->a($_) for 1 .. 10_000 ],
});
__END__
Benchmark reading...
Rate Moose Mouse Moo
Moose 43.3/s -- -60% -65%
Mouse 108/s 149% -- -13%
Moo 125/s 188% 15% --
--------
Benchmark writing...
Rate Moose Mouse Moo
Moose 32.5/s -- -64% -64%
Mouse 89.2/s 174% -- -1%
Moo 89.7/s 176% 1% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment