Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created July 30, 2018 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyink/be52a1de6b50bce2a2f60a3682bb633a to your computer and use it in GitHub Desktop.
Save tobyink/be52a1de6b50bce2a2f60a3682bb633a to your computer and use it in GitHub Desktop.
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