in reply to Memory efficiency, anonymous vs named's vs local subroutines
Anonymous subroutines use substantially less memory than named subroutines.
For the following simple subs (where nnnnnnn is a number between 0 .. 1e6):
sub Fnnnnnn { my( $a, $b, $c ) = @_; my $x = nnnnnn; return $a * $b - $c; } $f[ nnnnnn ] = sub { my( $a, $b, $c ) = @_; my $x = nnnnnn; return $a * $b - $c; }
The anonymous sub uses ~3k per sub whereas the named version uses ~4.5k per sub (64-bit perl 5.18).
Update: specious conclusion removed. (The eval was failing silently and assigning undef to the array.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Memory efficiency, anonymous vs named's vs local subroutines (anon < named )
by thanos1983 (Parson) on Jul 18, 2015 at 19:38 UTC | |
Re^2: Memory efficiency, anonymous vs named's vs local subroutines (anon < named )
by locked_user sundialsvc4 (Abbot) on Jul 18, 2015 at 13:58 UTC | |
by Anonymous Monk on Jul 18, 2015 at 14:06 UTC |