in reply to Re: Moose performance
in thread Moose performance
Not sure if the balance between performance and syntactic sugar is worth it.
Moose
$cat test_moose.pl package NumberHolder; use Moose; has 'x' => (is => 'rw', isa => 'Int'); has 'y' => (is => 'rw', isa => 'Int'); __PACKAGE__->meta->make_immutable; package Main; my $z = NumberHolder->new(x => 1, y => 2); print "z's x and y = ", $z->x()," ", $z->y(), "\n"; $time perl test_moose.pl z's x and y = 1 2 real 0m1.48s user 0m1.06s sys 0m0.11s
No Moose
$cat test_nomoose.pl package NumberRun; sub new { my $class = shift; my %args = @_; my %h = ( x => 0, y => 0); @h{ keys %args} = values %args; return bless \%h; } sub x { my $self = shift; $self->{x} = shift if @_; $self->{x}; } sub y { my $self = shift; $self->{y} = shift if @_; $self->{y}; } 1; package Main; use strict; use warnings; my $z = NumberRun->new(x => 1, y => 2); print "z's x and y = ", $z->x()," ", $z->y(), "\n"; $time perl test_nomoose.pl z's x and y = 1 2 real 0m0.07s user 0m0.01s sys 0m0.01s
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Moose performance
by Corion (Patriarch) on Nov 11, 2011 at 15:53 UTC | |
by Anonymous Monk on Nov 14, 2011 at 12:40 UTC | |
|
Re^3: Moose performance
by zwon (Abbot) on Nov 11, 2011 at 17:04 UTC | |
|
Re^3: Moose performance
by jethro (Monsignor) on Nov 11, 2011 at 17:09 UTC |