chomp white spaces
[gitmo/Mouse.git] / benchmarks / constructor.pl
CommitLineData
2e73a65c 1#!perl
2
3### MODULES
4
5
6{
7 package PlainMoose;
8 use Moose;
9 has foo => (is => 'rw');
10 has bar => (is => 'rw');
11 __PACKAGE__->meta->make_immutable();
12}
13{
14 package PlainMooseSC;
15 use Moose;
16 use MooseX::StrictConstructor;
17 has foo => (is => 'rw');
18 has bar => (is => 'rw');
19 __PACKAGE__->meta->make_immutable();
20}
21{
22 package PlainMouse;
23 use Mouse;
24 has foo => (is => 'rw');
25 has bar => (is => 'rw');
26 __PACKAGE__->meta->make_immutable();
27}
28{
29 package PlainMouseSC;
30 use Mouse;
31 has foo => (is => 'rw');
32 has bar => (is => 'rw');
33 __PACKAGE__->meta->make_immutable(strict_constructor => 1);
34}
35{
36 package CAF;
37 use warnings;
38 use strict;
39 use base 'Class::Accessor::Fast';
40 __PACKAGE__->mk_accessors(qw(foo bar));
41}
42
43use Benchmark qw(cmpthese);
44
45print "\nCREATION AND DESTRUCTION\n";
46cmpthese(-1, {
47 Moose => sub { my $x = PlainMoose->new(foo => 23, bar => 42) },
48 Mouse => sub { my $x = PlainMouse->new(foo => 23, bar => 42) },
49 MooseSC => sub { my $x = PlainMooseSC->new(foo => 23, bar => 42) },
50 MouseSC => sub { my $x = PlainMouseSC->new(foo => 23, bar => 42) },
51 ClassAccessorFast => sub { my $x = CAF->new({foo => 23, bar => 42}) },
52}, 'noc');