---
-- name: Construction of Point classes
+- name: Point classes
classes:
- 'MOP::Point'
- 'Plain::Point'
benchmarks:
- class: 'Bench::Construct'
+ name: object construction
args:
x: 7
y: 137
+ - class: 'Bench::Accessor'
+ name: accessor get
+ construct:
+ x: 4
+ y: 6
+ accessor: x
+ - class: 'Bench::Accessor'
+ name: accessor set
+ construct:
+ x: 4
+ y: 6
+ accessor: x
+ accessor_args: [ 5 ]
--- /dev/null
+#!/usr/bin/perl
+
+package Bench::Accessor;
+use Moose;
+use Moose::Util::TypeConstraints;
+
+eval {
+coerce ArrayRef
+ => from HashRef
+ => via { [ %$_ ] };
+};
+
+has class => (
+ isa => "Str",
+ is => "ro",
+);
+
+has construct => (
+ isa => "ArrayRef",
+ is => "ro",
+ auto_deref => 1,
+ coerce => 1,
+);
+
+has accessor => (
+ isa => "Str",
+ is => "ro",
+);
+
+has accessor_args => (
+ isa => "ArrayRef",
+ is => "ro",
+ auto_deref => 1,
+ coerce => 1,
+);
+
+sub code {
+ my $self = shift;
+
+ my $obj = $self->class->new( $self->construct );
+ my @accessor_args = $self->accessor_args;
+ my $accessor = $self->accessor;
+
+ sub { $obj->$accessor( @accessor_args ) };
+}
+
+__PACKAGE__;
+
+__END__
package Bench::Construct;
use Moose;
+use Moose::Util::TypeConstraints;
has class => (
isa => "Str",
is => "ro",
);
+eval {
+coerce ArrayRef
+ => from HashRef
+ => via { [ %$_ ] };
+};
+
has args => (
isa => "ArrayRef",
is => "ro",
auto_deref => 1,
+ coerce => 1,
);
sub code {
my $self = shift;
foreach my $bench ( $self->benchmarks ) {
- my $bench_class = $bench->{class};
- my @bench_args = ( (ref($bench->{args}) eq "ARRAY") ? @{ $bench->{args} } : %{ $bench->{args} } );
+ my $bench_class = delete $bench->{class};
+ my $name = delete $bench->{name} || $bench_class;
+ my @bench_args = %$bench;
eval "require $bench_class";
die $@ if $@;
$res{$class} = countit( $self->min_time, $b->code );
}
- print "$bench_class:\n";
+ print "- $name:\n";
cmpthese( \%res );
print "\n";
}
my $data = LoadFile( shift || "$FindBin::Bin/all.yml" );
foreach my $bench ( @$data ) {
- print delete $bench->{name}, "\n";
+ print "== ", delete $bench->{name}, " ==\n\n";
Bench::Run->new( %$bench )->run;
+ print "\n\n";
}