From: Peter Rabbitson Date: Sat, 13 Nov 2010 01:17:16 +0000 (+0100) Subject: Refactor object benchmarks even more X-Git-Tag: 0.009001~31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=80080483c651bb2ac145dce0526d8d372256ed60;p=gitmo%2FMoo.git Refactor object benchmarks even more --- diff --git a/benchmark/object_factory b/benchmark/object_factory index dae129d..14b0c40 100644 --- a/benchmark/object_factory +++ b/benchmark/object_factory @@ -74,32 +74,30 @@ for (1, 2) { my $objects; - print "\n\nBenching new()\n====================\n"; - - cmpthese ( -1, { map { - my $type = $_; - "${type}->new" => sub { - $objects->{$type} = $class_types->{$type}->new - for (1 .. $opts->{iterations}); + for my $use_attrs (0, 1) { + for my $attr (keys %$attrs_to_bench) { + printf "\n\nBenching %s ( %s )\n====================\n", + $attr, + $use_attrs + ? ($opts->{reuse} ? '' : 'new() and ' ) . 'get/set/get cycle' + : 'new() only' + , + ; + + cmpthese ( -1, { map { + my $type = $_; + "${type}->$attr" => sub { + $objects->{$type} = $class_types->{$type}->new + unless ( $use_attrs && $opts->{reuse} ); + + for (1 .. $opts->{iterations} ) { + my $init = $objects->{$type}->$attr; + $objects->{$type}->$attr('foo') unless $attr eq 'ro'; + my $set = $objects->{$type}->$attr; + } + }; + } keys %$class_types } ); } - } keys %$class_types } ); - - for my $attr (keys %$attrs_to_bench) { - print "\n\nBenching $attr\n====================\n"; - - cmpthese ( -1, { map { - my $type = $_; - "${type}->$attr" => sub { - $objects->{$type} = $class_types->{$type}->new - unless $opts->{reuse}; - - for (1 .. $opts->{iterations} ) { - my $init = $objects->{$type}->$attr; - $objects->{$type}->$attr('foo'); - my $set = $objects->{$type}->$attr; - } - } - } keys %$objects } ); } }