diff options
Diffstat (limited to 'benchmarks/cmop/lib/Bench/Run.pm')
-rw-r--r-- | benchmarks/cmop/lib/Bench/Run.pm | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/benchmarks/cmop/lib/Bench/Run.pm b/benchmarks/cmop/lib/Bench/Run.pm new file mode 100644 index 0000000..09ac1b6 --- /dev/null +++ b/benchmarks/cmop/lib/Bench/Run.pm @@ -0,0 +1,55 @@ +#!/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 = delete $bench->{class}; + my $name = delete $bench->{name} || $bench_class; + my @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 "- $name:\n"; + cmpthese( \%res ); + print "\n"; + } +} + +__PACKAGE__; + +__END__ |