From: "Jonathan E. Paton" <[EMAIL PROTECTED]> > > > Function calls in Perl are dead slow compared > > > to compiled languages. > > > > Ok, so why is this? > > > > Implementation and little optimization. > > Perl has a complex function calling mechanism, as > it flattens argument lists by pushing elements onto > the stack, records argument list length - the > number of arguments are variable in length.
Plus it keeps track of the call stack ... you can print out from where you were called, from where your caller has been called and so on. > Unlike many compiled languages, Perl does not > inline short/frequently called functions - with > the result that speed suffers. Well ... it does. But it only inlines the constant functions that have been seen before they were used. And they have to be specified as having no parameters! #!perl use Benchmark; sub postNOP { foreach (1..100_000) { nop(); } } sub nop {1}; sub postNNOP { foreach (1..100_000) { nnop(); } } sub nnop () {1}; sub Nop {1} sub preNOP { foreach (1..100_000) { Nop(); } } sub nNop () {1} sub preNNOP { foreach (1..100_000) { nNop(); } } sub Nothing { foreach (1..100_000) { } } timethese 100, { postNOP => \&postNOP, postNNOP => \&postNNOP, preNOP => \&preNOP, preNNOP => \&preNNOP, Nothing => \&Nothing }; __END__ Benchmark: timing 100 iterations of Nothing, postNNOP, postNOP, preNNOP, preNOP... Nothing: 3 wallclock secs ( 3.06 usr + 0.00 sys = 3.06 CPU) @ 32.64/s (n=100) postNNOP: 11 wallclock secs (10.97 usr + 0.00 sys = 10.97 CPU) @ 9.12/s (n=100) postNOP: 11 wallclock secs (10.96 usr + 0.00 sys = 10.96 CPU) @ 9.13/s (n=100) preNNOP: 3 wallclock secs ( 3.15 usr + 0.00 sys = 3.15 CPU) @ 31.71/s (n=100) preNOP: 11 wallclock secs (10.81 usr + 0.00 sys = 10.81 CPU) @ 9.25/s (n=100) Jenda =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]