Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Indeed; writing all those getters and setters manually is inconvenient.

use strict; use warnings; use Benchmark qw(cmpthese); use Time::Limit qw(20); package MOOSE { use Moose; has a => ( reader => 'get_a', writer => 'set_a', isa => 'Int', traits => ['Counter'], handles => { adjust_a => 'inc' }, ); has b => ( reader => 'get_b', writer => 'set_b', isa => 'Int', ); has c => ( reader => 'get_c', writer => 'set_c', isa => 'Int', ); __PACKAGE__->meta->make_immutable; } package OO { use Scalar::Util qw( looks_like_number ); sub new { bless $_[1], $_[0] } sub get_a{ my( $o ) = @_; $o->{a} }; sub set_a{ my( $o, $v ) = @_; $o->{a} = $v };; sub get_b{ my( $o ) = @_; $o->{b} }; sub set_b{ my( $o, $v ) = @_; $o->{b} = $v };; sub get_c{ my( $o ) = @_; $o->{c} }; sub set_c{ my( $o, $v ) = @_; $o->{c} = $v };; sub adjust_a{ my( $o ) = @_; $o->set_a( $o->get_a() + 1 ) }; } my @AoH1 = map 'OO'->new({ a=>1, b=>2, c=>3 }), 1 .. 3e4; my @AoH2 = map 'MOOSE'->new({ a=>1, b=>2, c=>3 }), 1 .. 3e4; cmpthese -3, { OO => sub { $_->adjust_a for @AoH1 }, MOOSE => sub { $_->adjust_a for @AoH2 }, };
Rate OO MOOSE OO 3.47/s -- -47% MOOSE 6.56/s 89% --
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

In reply to Re^2: Perl object memory overhead by tobyink
in thread Perl object memory overhead by Ineffectual

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2014-07-26 19:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (179 votes), past polls