added benchmark script for C::A::Fast
Tokuhiro Matsuno [Mon, 6 Apr 2009 02:30:46 +0000 (11:30 +0900)]
author/benchmarks/caf.pl [new file with mode: 0644]

diff --git a/author/benchmarks/caf.pl b/author/benchmarks/caf.pl
new file mode 100644 (file)
index 0000000..650ee54
--- /dev/null
@@ -0,0 +1,58 @@
+# benchmark
+use strict;
+use warnings;
+use Benchmark ':all';
+
+{
+    package Bench::CAF;
+    use base 'Class::Accessor::Fast';
+    __PACKAGE__->mk_accessors(qw/a/);
+}
+
+{
+    package Bench::Mouse;
+    use Mouse;
+    has 'a' => ( is => 'rw' );
+    no Mouse;
+    __PACKAGE__->meta->make_immutable;
+}
+
+my $c = Bench::CAF->new;
+my $m = Bench::Mouse->new;
+
+print "-- new\n";
+cmpthese(
+    -1, {
+        mouse => sub {
+            Bench::Mouse->new()
+        },
+        caf => sub {
+            Bench::CAF->new()
+        },
+    },
+);
+
+print "-- setter\n";
+cmpthese(
+    -1, {
+        mouse => sub {
+            $m->a(1);
+        },
+        caf => sub {
+            $c->a(1)
+        },
+    },
+);
+
+print "-- getter\n";
+cmpthese(
+    -1, {
+        mouse => sub {
+            $m->a;
+        },
+        caf => sub {
+            $c->a
+        },
+    },
+);
+