Commit | Line | Data |
43123819 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Benchmark qw[cmpthese]; |
7 | |
7623f774 |
8 | =pod |
9 | |
10 | This benchmark compares the overhead of a |
11 | auto-created type constraint vs. none at |
12 | all 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'); |
03aac1fa |
23 | #has 'boo' => (is => 'rw', isa => type 'CustomFoo' => where { blessed($_) && $_->isa('Foo') }); |
43123819 |
24 | } |
25 | |
26 | my $foo = Foo->new; |
27 | |
28 | cmpthese(200_000, |
29 | { |
30 | 'w/out_constraint' => sub { |
31 | $foo->baz($foo); |
32 | }, |
33 | 'w_constraint' => sub { |
34 | $foo->bar($foo); |
35 | }, |
03aac1fa |
36 | #'w_custom_constraint' => sub { |
37 | # $foo->boo($foo); |
38 | #}, |
43123819 |
39 | } |
40 | ); |
41 | |
42 | 1; |