From: gfx Date: Mon, 7 Dec 2009 06:01:57 +0000 (+0900) Subject: Add a benchmark for destructors X-Git-Tag: 0.43~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b988c856faa42d62dd70d5f0c3187bd4133764b0;p=gitmo%2FMouse.git Add a benchmark for destructors --- diff --git a/benchmarks/vs_caf_w_destructors.pl b/benchmarks/vs_caf_w_destructors.pl new file mode 100644 index 0000000..86fffe5 --- /dev/null +++ b/benchmarks/vs_caf_w_destructors.pl @@ -0,0 +1,43 @@ +#!perl + +### MODULES + + +{ + package PlainMoose; + use Moose; + has foo => (is => 'rw'); + + sub DEMOLISH { } + __PACKAGE__->meta->make_immutable(); +} +{ + package PlainMouse; + use Mouse; + has foo => (is => 'rw'); + + sub DEMOLISH { } + __PACKAGE__->meta->make_immutable(); +} +{ + package ClassAccessorFast; + use warnings; + use strict; + use base 'Class::Accessor::Fast'; + __PACKAGE__->mk_accessors(qw(foo)); + + sub DESTROY { } +} + +use Benchmark qw(cmpthese); + +my $moose = PlainMoose->new; +my $mouse = PlainMouse->new; +my $caf = ClassAccessorFast->new; + +print "\nCREATION AND DESTRUCTION\n"; +cmpthese(-1, { + Moose => sub { my $x = PlainMoose->new(foo => 23) }, + Mouse => sub { my $x = PlainMouse->new(foo => 23) }, + ClassAccessorFast => sub { my $x = ClassAccessorFast->new({foo => 23}) }, +}, 'noc');