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

Re: Subroutine overhead in Perl

by shmem (Chancellor)
on Nov 06, 2007 at 23:00 UTC ( [id://649362]=note: print w/replies, xml ) Need Help??


in reply to Subroutine overhead in Perl

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}

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2024-03-28 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found