X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=benchmarks%2Ftype_constraints2.pl;h=6e3e7134258c21a48c8f243d9b467107294c74db;hb=4de6e6a57d3054a4003bb05e79f75837d79cb50b;hp=b00fcbff3f1c9e1c28a3f7479987fe1e474b91d0;hpb=6fe3047524c6d3d68daedb8243d009015eb4b17c;p=gitmo%2FMoose.git diff --git a/benchmarks/type_constraints2.pl b/benchmarks/type_constraints2.pl index b00fcbf..6e3e713 100644 --- a/benchmarks/type_constraints2.pl +++ b/benchmarks/type_constraints2.pl @@ -81,6 +81,18 @@ inlining type constraints. __PACKAGE__->meta->make_immutable; } +{ + package Simple; + use Moose; + + has str => ( + is => 'rw', + isa => 'Str', + ); + + __PACKAGE__->meta->make_immutable; +} + my @ints = 1 .. 10; my @strs = 'a' .. 'j'; my @fhs = map { my $fh; open $fh, '<', $0 or die; $fh; } 1 .. 10; @@ -91,9 +103,23 @@ my %strs = map { $_ => $_ } @ints; my %fhs = map { $_ => $_ } @fhs; my %objects = map { $_ => $_ } @objects; +my $thing = Thing->new; +my $simple = Simple->new; + timethese( - 200_00, { - constructor => sub { + 1_000_000, { + constructor_simple => sub { + Simple->new( str => $strs[0] ); + }, + accessors_simple => sub { + $simple->str( $strs[0] ); + }, + } +); + +timethese( + 20_000, { + constructor_all => sub { Thing->new( int => $ints[0], str => $strs[0], @@ -109,9 +135,7 @@ timethese( h_object => \%objects, ); }, - accessors => sub { - my $thing = Thing->new; - + accessors_all => sub { $thing->int( $ints[0] ); $thing->str( $strs[0] ); $thing->fh( $fhs[0] );