X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=benchmarks%2Fclass_type.pl;fp=benchmarks%2Fclass_type.pl;h=4ab1eadf0367bfaf837e72edab1c9cfbcdfb252a;hp=0000000000000000000000000000000000000000;hb=53e42eacd228e35e5a0d9cf1b616e9de3579e302;hpb=c0c20aa6e94d349ee5e7d11b7f77d33882f250fe diff --git a/benchmarks/class_type.pl b/benchmarks/class_type.pl new file mode 100644 index 0000000..4ab1ead --- /dev/null +++ b/benchmarks/class_type.pl @@ -0,0 +1,68 @@ +#!perl +use strict; +use warnings; +use Benchmark qw/cmpthese/; + +{ + package Foo; + sub new{ bless {}, shift } +} + +eval q{ + package C::XSAOne; + use Class::XSAccessor + constructor => 'new', + accessors => { n => 'n' }, + ; + 1; +}; + +for my $klass (qw/Moose Mouse/) { + eval qq{ + package ${klass}One; + use $klass; + + has n => ( + is => 'rw', + isa => 'Foo', + ); + no $klass; + __PACKAGE__->meta->make_immutable; + }; + die $@ if $@; +} + +print "Class::MOP: $Class::MOP::VERSION\n"; +print "Moose: $Moose::VERSION\n"; +print "Mouse: $Mouse::VERSION\n"; +print "---- new\n"; + +my $foo = Foo->new(); + +my @classes = qw(Moose Mouse); +if(C::XSAOne->can('new')){ + push @classes, 'C::XSA'; +} + +cmpthese( + -1 => { + map { my $x = $_; $_ => sub { $x->new(n => $foo) } } + map { "${_}One" } @classes + } +); + +print "---- new,set\n"; +cmpthese( + -1 => { + map { my $y = $_; $_ => sub { $y->new(n => $foo)->n($foo) } } + map { "${_}One" } @classes + } +); + +print "---- set\n"; +my %c = map { $_ => "${_}One"->new(n => $foo) } @classes; +cmpthese( + -1 => { + map { my $y = $_; $_ => sub { $c{$y}->n($foo) } } @classes + } +);