Changelogging
[gitmo/Mouse.git] / author / benchmarks / basic.pl
CommitLineData
ddca6c8f 1use strict;
2use warnings;
3use Benchmark qw/cmpthese/;
4use String::TT qw/tt/;
5
6for my $klass (qw/Moose Mouse/) {
7 eval tt(q{
8 package [% klass %]One;
9 use [% klass %];
10 has n => (
11 is => 'rw',
12 isa => 'Int',
13 );
14 no [% klass %];
15 __PACKAGE__->meta->make_immutable;
16 });
17 die $@ if $@;
18}
19
dd034272 20print "Class::MOP: $Class::MOP::VERSION\n";
21print "Moose: $Moose::VERSION\n";
22print "Mouse: $Mouse::VERSION\n";
ddca6c8f 23print "---- new\n";
24cmpthese(
25 100000 => {
26 map { my $x = $_; $_ => sub { $x->new(n => 3) } }
27 map { "${_}One" }
28 qw/Moose Mouse/
29 }
30);
31
32print "---- new,set\n";
33cmpthese(
34 100000 => {
35 map { my $y = $_; $_ => sub { $y->new(n => 3)->n(5) } }
36 map { "${_}One" }
37 qw/Moose Mouse/
38 }
39);
b7e3d8b3 40
41print "---- set\n";
42my %c = map { $_ => "${_}One"->new(n => 3) } qw/Moose Mouse/;
43cmpthese(
44 100000 => {
45 map { my $y = $_; $_ => sub { $c{$y}->n(5) } }
46 qw/Moose Mouse/
47 }
48);
49
50print "---- get\n";
51cmpthese(
52 0 => {
53 map { my $y = $_; $_ => sub { $c{$y}->n() } }
54 qw/Moose Mouse/
55 }
56);
57