Skip to content

Instantly share code, notes, and snippets.

@schwern
Created July 31, 2014 20:11
Show Gist options
  • Select an option

  • Save schwern/b5774115432e8da81e0e to your computer and use it in GitHub Desktop.

Select an option

Save schwern/b5774115432e8da81e0e to your computer and use it in GitHub Desktop.
Moo speed up coercion + default with eval block instead of DIE handler.
{
package Foo;
use Moo;
has with_coerce1 => (
is => 'rw',
coerce => sub { 1 },
default => sub { 1 },
);
has with_coerce2 => (
is => 'rw',
coerce => sub { 1 },
default => sub { 1 },
);
has with_coerce3 => (
is => 'rw',
coerce => sub { 1 },
default => sub { 1 },
);
}
Foo->new for 1..1_000_000;
__END__
$ git branch
bug/rt.cpan.org-97653
* master
$ time perl -Ilib ~/tmp/test.plx
real 0m14.192s
user 0m14.170s
sys 0m0.018s
$ git co bug/rt.cpan.org-97653
Switched to branch 'bug/rt.cpan.org-97653'
$ git branch
* bug/rt.cpan.org-97653
master
$ time perl -Ilib ~/tmp/test.plx
real 0m4.733s
user 0m4.710s
sys 0m0.015s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment