From: Todd Hepler Date: Fri, 30 Mar 2012 18:49:33 +0000 (-0500) Subject: simplify and make $number_of_attributes X-Git-Tag: 2.0500~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=63f0e1ac4b6d03650b74760833420a361dad2e54;p=gitmo%2FMoose.git simplify and make $number_of_attributes The concerning part is comparing these: perl ./benchmarks/lotsa-classes.pl 1000 1 perl ./benchmarks/lotsa-classes.pl 1000 20 In the first case, all are in the "under a few seconds" category. In the second case Moose moves into ~30s land while the others pretty much stay in "under a few seconds". This is kinda expected since Moose is inlining constructors and accessors so that runtime can be faster. But in a sense, Moose isn't scaling as well as the others. --- diff --git a/benchmarks/lotsa-classes.pl b/benchmarks/lotsa-classes.pl index 8c846cc..701cd25 100644 --- a/benchmarks/lotsa-classes.pl +++ b/benchmarks/lotsa-classes.pl @@ -4,9 +4,9 @@ use warnings FATAL => 'all'; use strict; use File::Temp; use Path::Class; -use String::TT qw(tt strip); my $number_of_classes = shift || 1500; +my $number_of_attributes = shift || 20; my $t = shift || File::Temp->newdir; my $tmp = dir($t); $tmp->rmtree; @@ -17,59 +17,34 @@ $tmp->mkpath; my %class_writer = ( 'Moose' => sub { my $name = shift; - return strip tt q{ - package [% name %]; - use Moose; - has 'x' => ( is => 'ro', isa => 'Str' ); - __PACKAGE__->meta->make_immutable; - 1; - __END__ - }; + my $attrs = join '', map { "has '$_' => ( is => 'ro', isa => 'Str' );\n" } @_; + return qq{package $name;\nuse Moose;\n$attrs\n1;\n__END__\n}; }, 'Moo' => sub { my $name = shift; - return strip tt q{ - package [% name %]; - use Moo; - has 'x' => ( is => 'ro', isa => 'Str' ); - 1; - __END__ - }; + my $attrs = join'', map { "has '$_' => ( is => 'ro', isa => 'Str' );\n" } @_; + return qq{package $name;\nuse Moo;\n$attrs\n1;\n__END__\n}; }, 'Mo' => sub { my $name = shift; - return strip tt q{ - package [% name %]; - use Mo; - has 'x' => ( is => 'ro', isa => 'Str' ); - 1; - __END__ - }; + my $attrs = join'', map { "has '$_' => ( is => 'ro', isa => 'Str' );\n" } @_; + return qq{package $name;\nuse Mo;\n$attrs\n1;\n__END__\n}; }, 'Mouse' => sub { my $name = shift; - return strip tt q{ - package [% name %]; - use Mouse; - has 'x' => ( is => 'ro', isa => 'Str' ); - __PACKAGE__->meta->make_immutable; - 1; - __END__ - }; + my $attrs = join'', map { "has '$_' => ( is => 'ro', isa => 'Str' );\n" } @_; + return qq{package $name;\nuse Mouse;\n$attrs\n1;\n__END__\n}; }, 'plain-package' => sub { my $name = shift; - return strip tt q{ - package [% name %]; - sub x {} - 1; - __END__ - }; + my $attrs = join'', map { "sub $_ {}\n" } @_; + return qq{package $name;\n$attrs\n1;\n__END__\n}; }, ); my $class_prefix = 'TmpClassThingy'; my %lib_map; +my @attribute_names = map { 'a' . $_ } 1 .. $number_of_attributes; for my $module (sort keys %class_writer) { my $lib = $tmp->subdir($module . '-lib'); $lib->mkpath; @@ -77,11 +52,11 @@ for my $module (sort keys %class_writer) { for my $n (1 .. $number_of_classes) { my $class_name = $class_prefix . $n; my $fh = $lib->file($class_name . '.pm')->openw; - $fh->say($class_writer{$module}->($class_name)) or die; + $fh->say($class_writer{$module}->($class_name, @attribute_names)) or die; $fh->close or die; - $all_fh->say("use $class_name;"); + $all_fh->say("use $class_name;") or die; } - $all_fh->say('1;'); + $all_fh->say('1;') or die; $all_fh->close or die; $lib_map{$module} = $lib; }