add Bench::Run
[gitmo/Class-MOP.git] / bench / lib / Bench / Run.pm
1 #!/usr/bin/perl
2
3 package Bench::Run;
4 use Moose;
5
6 use Benchmark qw/:hireswallclock :all/;
7
8 has classes => (
9     isa => "ArrayRef",
10     is  => "rw",
11     auto_deref => 1,
12 );
13
14 has benchmarks => (
15     isa => "ArrayRef",
16     is  => "rw",
17     auto_deref => 1,
18 );
19
20 has min_time => (
21     isa => "Num",
22     is  => "rw",
23     default => 5,
24 );
25
26 sub run {
27     my $self = shift;
28
29     foreach my $bench ( $self->benchmarks ) {
30         my ( $bench_class, @bench_args ) = @$bench;
31         eval "require $bench_class";
32         die $@ if $@;
33         my %res;
34         foreach my $class ( $self->classes ) {
35             eval "require $class";
36             die $@ if $@;
37             my $b = $bench_class->new( @bench_args, class => $class );
38             $res{$class} = countit( $self->min_time, $b->code );
39         }
40
41         print "$bench_class:\n";
42         cmpthese( \%res );
43         print "\n";
44     }
45 }
46
47 __PACKAGE__;
48
49 __END__