X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=benchmarks%2Ftype_constraints.pl;h=e9b29f869a2c763a343ae60f193dc6bb676de562;hb=a559205a7d18e6fe2476d0710b253e6674804d9a;hp=a0a6eed36c29db16a1df34ca83a3e4c9bd18157a;hpb=c8cf9aaaa9bc89f8a889c3c17d163034dc59a410;p=gitmo%2FMoose.git diff --git a/benchmarks/type_constraints.pl b/benchmarks/type_constraints.pl index a0a6eed..e9b29f8 100644 --- a/benchmarks/type_constraints.pl +++ b/benchmarks/type_constraints.pl @@ -7,8 +7,8 @@ use Benchmark qw[cmpthese]; =pod -This benchmark compares the overhead of a -auto-created type constraint vs. none at +This benchmark compares the overhead of a +auto-created type constraint vs. none at all vs. a custom-created type. =cut @@ -17,21 +17,36 @@ all vs. a custom-created type. package Foo; use Moose; use Moose::Util::TypeConstraints; - + has 'baz' => (is => 'rw'); has 'bar' => (is => 'rw', isa => 'Foo'); } +{ + package Bar; + + sub new { bless {} => __PACKAGE__ } + sub bar { + my $self = shift; + $self->{bar} = shift if @_; + $self->{bar}; + } +} + my $foo = Foo->new; +my $bar = Bar->new; -cmpthese(200_000, +cmpthese(200_000, { + 'hand coded' => sub { + $bar->bar($bar); + }, 'w/out_constraint' => sub { $foo->baz($foo); }, 'w_constraint' => sub { - $foo->bar($foo); - }, + $foo->bar($foo); + }, } );