speed of subroutine calls in perl

Discussion in 'Perl Misc' started by Rainer Weikusat, Jul 5, 2013.

  1. 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
     
    Rainer Weikusat, Jul 5, 2013
    #1
    1. Advertising

  2. >>>>> "RW" == Rainer Weikusat <> writes:

    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




    --
    Charlton Wilbur
     
    Charlton Wilbur, Jul 6, 2013
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ham

    I need speed Mr .Net....speed

    Ham, Oct 28, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    2,372
    Antony Baula
    Oct 29, 2004
  2. nospam

    How to speed up subroutine?

    nospam, Aug 26, 2004, in forum: Perl
    Replies:
    1
    Views:
    465
  3. efiedler
    Replies:
    1
    Views:
    2,131
    Tim Ward
    Oct 9, 2003
  4. king
    Replies:
    5
    Views:
    210
  5. Rainer Weikusat

    speed of subroutine calls in perl

    Rainer Weikusat, Jul 5, 2013, in forum: Perl Misc
    Replies:
    0
    Views:
    159
    Rainer Weikusat
    Jul 5, 2013
Loading...

Share This Page