add an easy benchmark harness
Yuval Kogman [Wed, 28 Jun 2006 13:52:26 +0000 (13:52 +0000)]
bench/all.yml [new file with mode: 0644]
bench/lib/Bench/Run.pm
bench/run_yml.pl [new file with mode: 0644]

diff --git a/bench/all.yml b/bench/all.yml
new file mode 100644 (file)
index 0000000..093a833
--- /dev/null
@@ -0,0 +1,11 @@
+---
+- name: Construction of Point classes
+  classes:
+  - 'MOP::Point'
+  - 'Plain::Point'
+  benchmarks:
+    - class: 'Bench::Construct'
+      args:
+        x: 7
+        y: 137
+
index dffb121..fc2009f 100644 (file)
@@ -27,13 +27,18 @@ sub run {
     my $self = shift;
 
     foreach my $bench ( $self->benchmarks ) {
-        my ( $bench_class, @bench_args ) = @$bench;
+        my $bench_class = $bench->{class};
+        my @bench_args  = ( (ref($bench->{args}) eq "ARRAY") ? @{ $bench->{args} } : %{ $bench->{args} } );
+
         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 );
         }
diff --git a/bench/run_yml.pl b/bench/run_yml.pl
new file mode 100644 (file)
index 0000000..409de84
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use YAML::Syck;
+use Bench::Run;
+
+my $data = LoadFile( shift || "$FindBin::Bin/all.yml" );
+
+foreach my $bench ( @$data ) {
+    print delete $bench->{name}, "\n";
+    Bench::Run->new( %$bench )->run;
+}
+
+