speed of subroutine calls in perl

  • Thread starter Rainer Weikusat
  • Start date
R

Rainer Weikusat

I recently read the 'Lambda: The ultimate GOTO' paper published by
Steele/ Sussman in 1977[*]. While I mostly consider this 'an
entertaining rant', the idea that The Absolutely Dreadful Function
Call Overhead[tm] is rather an urban legend people keep telling each
other seemed plausible to me. Of course, just as in any other
language, it is well-known that "subroutine [...] calls are horribly
slow" in perl[**]. Because I wanted to know what precisely 'horribly
slow' means, I wrote the following small test program:

------------
use Benchmark;

sub perl_dummy
{
return 1;
}

timethese(-1,
{
perl_dummy => sub { perl_dummy(); },
empty => sub { return 1; }});
------------

The results I got from that (averaging four runs and substracting the
average 'empty' speed from the average 'perl_dummy' speed) was that a
pure subroutine call alone takes about 1.36E-7 seconds for perl 5.10.1
running on a 3.2Ghz Core i3 computer. When using 1,2,3 as argument
list for perl_dummy, the time needed to call it (calculated in the
same way) was about 1.74E-7s. In line with the thesis from the paper,
I think that people are rather 'horrified' by function calls because
they are function calls (... and everyone knows that ...) than by the
prospect of runing some code which needs less than 0.0000002 to
execute.

[*]
http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-443.pdf

[**]
http://c2.com/cgi/wiki?WhyHatePerl
 
C

Charlton Wilbur

RW> I recently read the 'Lambda: The ultimate GOTO' paper published
RW> by Steele/ Sussman in 1977[*]. While I mostly consider this 'an
RW> entertaining rant', the idea that The Absolutely Dreadful
RW> Function Call Overhead[tm] is rather an urban legend people keep
RW> telling each other seemed plausible to me.

You are aware that processors have gotten considerably faster in the
intervening 36 years, no? You do understand that an overhead of 20
cycles when your cycles per second is measured in the hundreds is
considerably more of a problem than an overhead of 20 cycles when your
cycles per second is measured in the millions?

Or are you going to ask, next, how Bill Gates could *possibly* have
thought 640K would be enough for everyone when your last computer
shipped with 4M?

Charlton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top