summaryrefslogtreecommitdiff
path: root/benchmarks/type_constraints.pl
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /benchmarks/type_constraints.pl
downloadMoose-tarball-master.tar.gz
Diffstat (limited to 'benchmarks/type_constraints.pl')
-rw-r--r--benchmarks/type_constraints.pl53
1 files changed, 53 insertions, 0 deletions
diff --git a/benchmarks/type_constraints.pl b/benchmarks/type_constraints.pl
new file mode 100644
index 0000000..e9b29f8
--- /dev/null
+++ b/benchmarks/type_constraints.pl
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Benchmark qw[cmpthese];
+
+=pod
+
+This benchmark compares the overhead of a
+auto-created type constraint vs. none at
+all vs. a custom-created type.
+
+=cut
+
+{
+ 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,
+ {
+ 'hand coded' => sub {
+ $bar->bar($bar);
+ },
+ 'w/out_constraint' => sub {
+ $foo->baz($foo);
+ },
+ 'w_constraint' => sub {
+ $foo->bar($foo);
+ },
+ }
+);
+
+1; \ No newline at end of file