fix punctuation
[gitmo/Moose.git] / benchmarks / type_constraints.pl
CommitLineData
43123819 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Benchmark qw[cmpthese];
7
7623f774 8=pod
9
d03bd989 10This benchmark compares the overhead of a
11auto-created type constraint vs. none at
7623f774 12all vs. a custom-created type.
13
14=cut
15
43123819 16{
17 package Foo;
18 use Moose;
19 use Moose::Util::TypeConstraints;
d03bd989 20
43123819 21 has 'baz' => (is => 'rw');
22 has 'bar' => (is => 'rw', isa => 'Foo');
43123819 23}
24
8ecb1fa0 25{
26 package Bar;
d03bd989 27
8ecb1fa0 28 sub new { bless {} => __PACKAGE__ }
d03bd989 29 sub bar {
8ecb1fa0 30 my $self = shift;
31 $self->{bar} = shift if @_;
32 $self->{bar};
33 }
34}
35
43123819 36my $foo = Foo->new;
8ecb1fa0 37my $bar = Bar->new;
43123819 38
d03bd989 39cmpthese(200_000,
43123819 40 {
8ecb1fa0 41 'hand coded' => sub {
42 $bar->bar($bar);
43 },
43123819 44 'w/out_constraint' => sub {
45 $foo->baz($foo);
46 },
47 'w_constraint' => sub {
d03bd989 48 $foo->bar($foo);
49 },
43123819 50 }
51);
52
531;