From: gfx Date: Fri, 25 Sep 2009 09:35:37 +0000 (+0900) Subject: Add a benchmark based on author/bencharks/basic.pl X-Git-Tag: 0.35~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4402b4bc9b8c1a5db72d044dabc7e0217ac42454;p=gitmo%2FMouse.git Add a benchmark based on author/bencharks/basic.pl --- diff --git a/benchmarks/basic.pl b/benchmarks/basic.pl new file mode 100644 index 0000000..e53c836 --- /dev/null +++ b/benchmarks/basic.pl @@ -0,0 +1,57 @@ +#!perl +use strict; +use warnings; +use Benchmark qw/cmpthese/; + +for my $klass (qw/Moose Mouse/) { + eval qq{ + package ${klass}One; + use $klass; + has n => ( + is => 'rw', + isa => 'Int', + ); + no $klass; + __PACKAGE__->meta->make_immutable; + }; + die $@ if $@; +} + +print "Class::MOP: $Class::MOP::VERSION\n"; +print "Moose: $Moose::VERSION\n"; +print "Mouse: $Mouse::VERSION\n"; +print "---- new\n"; +cmpthese( + -1 => { + map { my $x = $_; $_ => sub { $x->new(n => 3) } } + map { "${_}One" } + qw/Moose Mouse/ + } +); + +print "---- new,set\n"; +cmpthese( + -1 => { + map { my $y = $_; $_ => sub { $y->new(n => 3)->n(5) } } + map { "${_}One" } + qw/Moose Mouse/ + } +); + +print "---- set\n"; +my %c = map { $_ => "${_}One"->new(n => 3) } qw/Moose Mouse/; +cmpthese( + -1 => { + map { my $y = $_; $_ => sub { $c{$y}->n(5) } } + qw/Moose Mouse/ + } +); + +print "---- get\n"; +cmpthese( + -1 => { + map { my $y = $_; $_ => sub { $c{$y}->n() } } + qw/Moose Mouse/ + } +); +