Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It was pretty obviuos my search algorithm was way more efficient than his and the only answer I could come up for the difference was that Perl must pay a lot in overhead for subroutines and or recursion.

Yes, indeed. Calling a perl subroutine isn't just saving the return address, jumping to a location in memory and executing from there until return hits.

From what I have grasped from the highly bewildering perl source code, entering a subroutine means setting up a scope with all its tidbits and pushing it onto the execution stack, with all stuff like aliasing @_ and such, and tearing that whole structure down after being done with it; there's a lot going on under the hood (have a look at PP(pp_entersub) in pp_hot.c in the perl source tree) which means a lot of memory allocation, testing and shifting bits, freeing and so on.

Perl subroutines are truly dynamic; they can be altered at runtime, they might be functions, methods, autoloaded subs, ... - and they have to deal with what is the glory of perl - context, which also might be dynamic.

I don't know anything of the execution model of Java that would surpass what a pig knows of what sunday is, but I guess things are much simpler on that side of the programming world.

Not that I know much of perls internals either, and this is post is meant with a lot of handwaving. Would be nice if somebody with a deeper knowledge of perl corrected and/or expanded my blurry statements.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Subroutine overhead in Perl by shmem
in thread Subroutine overhead in Perl by enemyofthestate

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-04-25 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found