Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use strict;
use warnings;
use Benchmark qw(cmpthese);
package Local::Moose::Native {
use Moose;
has foo => (is => 'rw', isa => 'Int');
}
package Local::Moose::TypeTiny {
use Moose;
use Types::Standard qw(Int);
has foo => (is => 'rw', isa => Int);
}
package Local::Moo::Native {
use Moo;
has foo => (is => 'rw', isa => sub { my $value = shift; $value =~ /\A-?[1-9][0-9]*\z/ or die });
}
package Local::Moo::TypeTiny {
use Moo;
use Types::Standard qw(Int);
has foo => (is => 'rw', isa => Int);
}
sub mkcode {
my $class = shift;
sub { my $obj = $class->new(foo => 1); $obj->foo($obj->foo + 1) for 1..1000 };
}
cmpthese -1, {
map { $_ => mkcode($_) } qw(
Local::Moose::Native
Local::Moose::TypeTiny
Local::Moo::Native
Local::Moo::TypeTiny
)
};
__END__
Rate Local::Moo::TypeTiny Local::Moo::Native Local::Moose::Native Local::Moose::TypeTiny
Local::Moo::TypeTiny 482/s -- -12% -52% -53%
Local::Moo::Native 550/s 14% -- -45% -46%
Local::Moose::Native 1008/s 109% 83% -- -1%
Local::Moose::TypeTiny 1017/s 111% 85% 1% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment