foo
[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
10This benchmark compares the overhead of a
11auto-created type constraint vs. none at
12all vs. a custom-created type.
13
14=cut
15
43123819 16{
17 package Foo;
18 use Moose;
19 use Moose::Util::TypeConstraints;
20
21 has 'baz' => (is => 'rw');
22 has 'bar' => (is => 'rw', isa => 'Foo');
43123819 23}
24
25my $foo = Foo->new;
26
27cmpthese(200_000,
28 {
29 'w/out_constraint' => sub {
30 $foo->baz($foo);
31 },
32 'w_constraint' => sub {
33 $foo->bar($foo);
c8cf9aaa 34 },
43123819 35 }
36);
37
381;