From: Yuval Kogman Date: Wed, 28 Jun 2006 13:41:45 +0000 (+0000) Subject: add Bench::Run X-Git-Tag: 0_33~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b07c7a9d7bbed16e9a5a15e9412fc8384f74102f;p=gitmo%2FClass-MOP.git add Bench::Run --- diff --git a/bench/lib/Bench/Construct.pm b/bench/lib/Bench/Construct.pm new file mode 100644 index 0000000..6eb90f9 --- /dev/null +++ b/bench/lib/Bench/Construct.pm @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +package Bench::Construct; +use Moose; + +has class => ( + isa => "Str", + is => "ro", +); + +has args => ( + isa => "ArrayRef", + is => "ro", + auto_deref => 1, +); + +sub code { + my $self = shift; + + my $class = $self->class; + my @args = $self->args; + + sub { my $obj = $class->new( @args ) } +} + +__PACKAGE__; + +__END__ diff --git a/bench/lib/Bench/Run.pm b/bench/lib/Bench/Run.pm new file mode 100644 index 0000000..dffb121 --- /dev/null +++ b/bench/lib/Bench/Run.pm @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +package Bench::Run; +use Moose; + +use Benchmark qw/:hireswallclock :all/; + +has classes => ( + isa => "ArrayRef", + is => "rw", + auto_deref => 1, +); + +has benchmarks => ( + isa => "ArrayRef", + is => "rw", + auto_deref => 1, +); + +has min_time => ( + isa => "Num", + is => "rw", + default => 5, +); + +sub run { + my $self = shift; + + foreach my $bench ( $self->benchmarks ) { + my ( $bench_class, @bench_args ) = @$bench; + eval "require $bench_class"; + die $@ if $@; + my %res; + foreach my $class ( $self->classes ) { + eval "require $class"; + die $@ if $@; + my $b = $bench_class->new( @bench_args, class => $class ); + $res{$class} = countit( $self->min_time, $b->code ); + } + + print "$bench_class:\n"; + cmpthese( \%res ); + print "\n"; + } +} + +__PACKAGE__; + +__END__ diff --git a/bench/lib/Plain/Point.pm b/bench/lib/Plain/Point.pm index 602165c..276f493 100644 --- a/bench/lib/Plain/Point.pm +++ b/bench/lib/Plain/Point.pm @@ -36,7 +36,7 @@ sub y { sub clear { my $self = shift; - @{ $self-> }{qw/x y/} = (0, 0); + @{$self}{qw/x y/} = (0, 0); } __PACKAGE__;