X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=benchmarks%2Fsubtype.pl;fp=benchmarks%2Fsubtype.pl;h=5c53508d2b698ee40cf861a71ff19c9b2ad25b7a;hb=d03295d720223421e5878677fd4cb66b62f92a67;hp=0000000000000000000000000000000000000000;hpb=62225dfe344ee4caa7706570303159a775c07273;p=gitmo%2FMouse.git diff --git a/benchmarks/subtype.pl b/benchmarks/subtype.pl new file mode 100755 index 0000000..5c53508 --- /dev/null +++ b/benchmarks/subtype.pl @@ -0,0 +1,58 @@ +#!perl +use strict; +use warnings; +use Benchmark qw/cmpthese/; + +for my $klass (qw/Moose Mouse/) { + eval qq{ + package ${klass}One; + use $klass; + use ${klass}::Util::TypeConstraints; + + subtype 'NaturalNumber', as 'Int', where { \$_ > 0 }; + + has n => ( + is => 'rw', + isa => 'NaturalNumber', + ); + no $klass; + __PACKAGE__->meta->make_immutable; + }; + die $@ if $@; +} + +use Data::Dumper; +$Data::Dumper::Deparse = 1; +$Data::Dumper::Indent = 1; +print Mouse::Util::TypeConstraints::find_type_constraint('NaturalNumber')->dump(3); +print Moose::Util::TypeConstraints::find_type_constraint('NaturalNumber')->dump(3); + +print "Class::MOP: $Class::MOP::VERSION\n"; +print "Moose: $Moose::VERSION\n"; +print "Mouse: $Mouse::VERSION\n"; +print "---- new\n"; +cmpthese( + -1 => { + map { my $x = $_; $_ => sub { $x->new(n => 3) } } + map { "${_}One" } + qw/Moose Mouse/ + } +); + +print "---- new,set\n"; +cmpthese( + -1 => { + map { my $y = $_; $_ => sub { $y->new(n => 3)->n(5) } } + map { "${_}One" } + qw/Moose Mouse/ + } +); + +print "---- set\n"; +my %c = map { $_ => "${_}One"->new(n => 3) } qw/Moose Mouse/; +cmpthese( + -1 => { + map { my $y = $_; $_ => sub { $c{$y}->n(5) } } + qw/Moose Mouse/ + } +);