Created
April 13, 2014 16:11
-
-
Save schwern/10590432 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use v5.10; | |
| use strict; | |
| use warnings; | |
| use Benchmark qw(cmpthese); | |
| { | |
| package MyMoo; | |
| use Moo; | |
| use Sub::Quote; | |
| use MooX::Types::MooseLike::Base qw(:all); | |
| has isa_rw_int_sub => | |
| is => 'rw', | |
| isa => sub { | |
| die "$_[0] is not an integer!" unless $_[0] =~ /^[+-]?\d+$/; | |
| }; | |
| has isa_rw_int_qs => | |
| is => 'rw', | |
| isa => quote_sub(q{ | |
| die "$_[0] is not an integer!" unless $_[0] =~ /^[+-]?\d+$/ | |
| }); | |
| has isa_rw_int_ml => | |
| is => 'rw', | |
| isa => Int; | |
| } | |
| { | |
| package MyMouse; | |
| use Mouse; | |
| has isa_rw_int => | |
| is => 'rw', | |
| isa => 'Int'; | |
| no Mouse; | |
| __PACKAGE__->meta->make_immutable(); | |
| } | |
| { | |
| package MyMoose; | |
| use Moose; | |
| has isa_rw_int => | |
| is => 'rw', | |
| isa => 'Int'; | |
| no Moose; | |
| __PACKAGE__->meta->make_immutable(); | |
| } | |
| my $moo = MyMoo->new(); | |
| my $mouse = MyMouse->new; | |
| my $moose = MyMoose->new; | |
| say "Writing"; | |
| cmpthese( shift || 4_000_000, { | |
| moose_int => sub { $moose->isa_rw_int(23) }, | |
| mouse_int => sub { $mouse->isa_rw_int(23) }, | |
| moo_int_qs => sub { $moo->isa_rw_int_qs(23) }, | |
| moo_int_sub => sub { $moo->isa_rw_int_sub(23) }, | |
| moo_int_ml => sub { $moo->isa_rw_int_ml(23) }, | |
| }); | |
| say "Reading"; | |
| cmpthese( shift || 4_000_000, { | |
| moose_int => sub { $moose->isa_rw_int() }, | |
| mouse_int => sub { $mouse->isa_rw_int() }, | |
| moo_int_qs => sub { $moo->isa_rw_int_qs() }, | |
| moo_int_sub => sub { $moo->isa_rw_int_sub() }, | |
| moo_int_ml => sub { $moo->isa_rw_int_ml() }, | |
| }); | |
| __END__ | |
| Writing | |
| Rate moo_int_ml moo_int_sub moo_int_qs moose_int mouse_int | |
| moo_int_ml 157853/s -- -17% -19% -67% -97% | |
| moo_int_sub 189125/s 20% -- -3% -60% -97% | |
| moo_int_qs 194647/s 23% 3% -- -59% -97% | |
| moose_int 472813/s 200% 150% 143% -- -92% | |
| mouse_int 5633803/s 3469% 2879% 2794% 1092% -- | |
| Reading | |
| Rate moose_int moo_int_ml moo_int_qs moo_int_sub mouse_int | |
| moose_int 2395210/s -- -6% -9% -14% -72% | |
| moo_int_ml 2547771/s 6% -- -3% -8% -70% | |
| moo_int_qs 2631579/s 10% 3% -- -5% -69% | |
| moo_int_sub 2777778/s 16% 9% 6% -- -67% | |
| mouse_int 8510638/s 255% 234% 223% 206% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment