From: gfx Date: Sat, 20 Feb 2010 12:50:57 +0000 (+0900) Subject: Add a benchmark for strict constructors X-Git-Tag: 0.50_03~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2e73a65cd1979ba31f6b100a1b7ae6710a3241c9;p=gitmo%2FMouse.git Add a benchmark for strict constructors --- diff --git a/benchmarks/constructor.pl b/benchmarks/constructor.pl new file mode 100644 index 0000000..8dc713b --- /dev/null +++ b/benchmarks/constructor.pl @@ -0,0 +1,52 @@ +#!perl + +### MODULES + + +{ + package PlainMoose; + use Moose; + has foo => (is => 'rw'); + has bar => (is => 'rw'); + __PACKAGE__->meta->make_immutable(); +} +{ + package PlainMooseSC; + use Moose; + use MooseX::StrictConstructor; + has foo => (is => 'rw'); + has bar => (is => 'rw'); + __PACKAGE__->meta->make_immutable(); +} +{ + package PlainMouse; + use Mouse; + has foo => (is => 'rw'); + has bar => (is => 'rw'); + __PACKAGE__->meta->make_immutable(); +} +{ + package PlainMouseSC; + use Mouse; + has foo => (is => 'rw'); + has bar => (is => 'rw'); + __PACKAGE__->meta->make_immutable(strict_constructor => 1); +} +{ + package CAF; + use warnings; + use strict; + use base 'Class::Accessor::Fast'; + __PACKAGE__->mk_accessors(qw(foo bar)); +} + +use Benchmark qw(cmpthese); + +print "\nCREATION AND DESTRUCTION\n"; +cmpthese(-1, { + Moose => sub { my $x = PlainMoose->new(foo => 23, bar => 42) }, + Mouse => sub { my $x = PlainMouse->new(foo => 23, bar => 42) }, + MooseSC => sub { my $x = PlainMooseSC->new(foo => 23, bar => 42) }, + MouseSC => sub { my $x = PlainMouseSC->new(foo => 23, bar => 42) }, + ClassAccessorFast => sub { my $x = CAF->new({foo => 23, bar => 42}) }, +}, 'noc');