MooでMooX::Types::MooseLike::Baseったら遅い件
benchはこちらのものを参考に作りなおしてます。
Benchmark: timing 300000 iterations of moo_direct, moo_ro, moo_rw, moose_direct, moose_ro, moose_rw, mouse_direct, mouse_ro, mouse_rw... moo_direct: 0 wallclock secs ( 0.10 usr + 0.00 sys = 0.10 CPU) @ 3000000.00/s (n=300000) (warning: too few iterations for a reliable count) moo_ro: 1 wallclock secs ( 0.62 usr + 0.00 sys = 0.62 CPU) @ 483870.97/s (n=300000) moo_rw: 1 wallclock secs ( 0.58 usr + 0.00 sys = 0.58 CPU) @ 517241.38/s (n=300000) moose_direct: 0 wallclock secs ( 0.10 usr + 0.00 sys = 0.10 CPU) @ 3000000.00/s (n=300000) (warning: too few iterations for a reliable count) moose_ro: 1 wallclock secs ( 0.68 usr + 0.00 sys = 0.68 CPU) @ 441176.47/s (n=300000) moose_rw: 1 wallclock secs ( 0.70 usr + 0.00 sys = 0.70 CPU) @ 428571.43/s (n=300000) mouse_direct: 0 wallclock secs ( 0.10 usr + 0.00 sys = 0.10 CPU) @ 3000000.00/s (n=300000) (warning: too few iterations for a reliable count) mouse_ro: 0 wallclock secs ( 0.21 usr + 0.00 sys = 0.21 CPU) @ 1428571.43/s (n=300000) (warning: too few iterations for a reliable count) mouse_rw: 0 wallclock secs ( 0.19 usr + 0.00 sys = 0.19 CPU) @ 1578947.37/s (n=300000) (warning: too few iterations for a reliable count) Rate moose_rw moose_ro moo_ro moo_rw mouse_ro mouse_rw mouse_direct moose_direct moo_direct moose_rw 428571/s -- -3% -11% -17% -70% -73% -86% -86% -86% moose_ro 441176/s 3% -- -9% -15% -69% -72% -85% -85% -85% moo_ro 483871/s 13% 10% -- -6% -66% -69% -84% -84% -84% moo_rw 517241/s 21% 17% 7% -- -64% -67% -83% -83% -83% mouse_ro 1428571/s 233% 224% 195% 176% -- -10% -52% -52% -52% mouse_rw 1578947/s 268% 258% 226% 205% 11% -- -47% -47% -47% mouse_direct 3000000/s 600% 580% 520% 480% 110% 90% -- 0% -0% moose_direct 3000000/s 600% 580% 520% 480% 110% 90% 0% -- -0% moo_direct 3000000/s 600% 580% 520% 480% 110% 90% 0% 0% --
mooseとmooがそんな変わらなくて、mouseが他の3倍速いみたいな結果になってしまった。
ちなみにMooの分だけの実装はこちら
package ClassMoo; use Moo; use MooX::Types::MooseLike::Base qw(:all); has 'ro1' => ( is => 'ro', isa => Bool, default => 1 ); has 'ro2' => ( is => 'ro', isa => Int, default => 1 ); has 'ro3' => ( is => 'ro', isa => Str , default => '1' ); has 'ro4' => ( is => 'ro', isa => ArrayRef , default => sub { [] }); has 'ro5' => ( is => 'ro', isa => HashRef , default => sub { {} }); has 'ro6' => ( is => 'ro', isa => CodeRef , default => sub { sub {1} }); has 'rw1' => ( is => 'rw', isa => Bool, default => 1 ); has 'rw2' => ( is => 'rw', isa => Int, default => 1 ); has 'rw3' => ( is => 'rw', isa => Str , default => '1' ); has 'rw4' => ( is => 'rw', isa => ArrayRef , default => sub { [] }); has 'rw5' => ( is => 'rw', isa => HashRef , default => sub { {} }); has 'rw6' => ( is => 'rw', isa => CodeRef , default => sub { sub {1} }); __PACKAGE__->meta->make_immutable; 1;
(>_<)ムー
追記(2013/03/17 23:29)
なんかLingrの方でコメントされてました。
比較したらMouseよりも遅いけど、現実的には問題ない程度には遅くないってことですね。