Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Memory efficiency, anonymous vs named's vs local subroutines (anon < named )

by BrowserUk (Patriarch)
on Jul 18, 2015 at 11:19 UTC ( [id://1135301]=note: print w/replies, xml ) Need Help??


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.)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
  • Comment on Re: Memory efficiency, anonymous vs named's vs local subroutines (anon < named )
  • Download Code

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

    Hello BrowserUk,

    Thank you for your time and effort, reading and replying to my question. Nice, thanks for the information that I was looking.

    But I guess it seems I will stay with simple named functions to my scripts from now on. Unless it is necessary to work differently (rear case).

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re^2: Memory efficiency, anonymous vs named's vs local subroutines (anon < named )
by sundialsvc4 (Abbot) on Jul 18, 2015 at 13:58 UTC

    I’m sorry, BrowserUK, but I really don’t quite understand the last sentence in that post.   There is no eval statement in what remains, and therefore I really don’t know if you meant to retract the assertion that you made in the first sentence of your post.   I also don’t quite see the point of your code-sample since it does not appear (as it stands now) to be either complete or runnable.

    Ergo, “huh?”

    I implicitly assume, always, that “you know whereof you speak,” and especially that you ordinarily work in resource-intensive applications, but I do not grok what you are trying to say here.   Maybe it’s the consequence of previous-versions and edits that I never saw?

    Please clarify, preferably in a reply to, vs. a rewrite of, the above post.   Thank you.

      You don't even mark updates to your own nodes (example), so you don't get to complain to others.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-24 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found