Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Perl object memory overhead

by BrowserUk (Pope)
on Mar 28, 2014 at 02:00 UTC ( #1080032=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    @AoH = map{ a=>1, b=>2, c=>3 }, 1 .. 3e6;;
    say total_size( \@AoH );;
    936000209
    
  2. or download this
    bless $_, 'OO' for @AoH;;
    say total_size( \@AoH );;
    936000209
    
  3. or download this
    sub OO::a{ $_[0]->{a}=$_[1] if defined $_[1]; $_[0]->{a} };;
    $t = time; 
    $_->a( $_->a() +1 ) for @AoH; 
    say time - $t;;;
    4.60931897163391
    
  4. or download this
    $t = time; 
    ++$_->{a} for @AoH; 
    say time() - $t;;
    0.931627988815308
    
  5. or download this
    sub OO::get_a{ $_[0]->{a} }; sub OO::set_a{ $_[0]->{a} = $_[1] };;
    sub OO::get_b{ $_[0]->{b} }; sub OO::set_b{ $_[0]->{b} = $_[1] };;
    ...
    $_->adjust_a() for @AoH; 
    say time() - $t;;
    4.95501685142517
    
  6. or download this
    sub OO::get_a{ my( $o ) = @_; $o->{a} }; sub OO::set_a{ my( $o, $v ) =
    + @_; $o->{a} = $v };;
    sub OO::get_b{ my( $o ) = @_; $o->{b} }; sub OO::set_b{ my( $o, $v ) =
    + @_; $o->{b} = $v };;
    ...
    $_->adjust_a() for @AoH; 
    say time() - $t;;
    6.20793199539185
    
  7. or download this
    sub OO::get_a{ my( $o ) = @_; die unless ref( $o ) eq 'OO'; $o->{a} };
    + 
    sub OO::set_a{ my( $o, $v ) = @_; die unless ref( $o ) eq 'OO'; die un
    +less looks_like_number( $v ); $o->{a} = $v };;
    ...
    $_->adjust_a() for @AoH; 
    say time() - $t;;
    8.23622608184814
    
  8. or download this
    use Moose;
    
    ...
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1080032]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2014-09-19 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (140 votes), past polls