Speed of Python vs. Perl

Tim Peters tim.one at home.com
Thu Jan 11 21:01:28 EST 2001


[Tim]
> Indeed, on my box, I can clearly see the difference between:
>     python -c "print 'hi'"
> and
>     perl -e "print 'hi'"
> by eyeball (the former takes a noticeable fraction of a second;
> the latter appears instantaneous).

[Skip Montanaro]
> Then you have better reflexes than anyone suspected

There you go, projecting your limitations onto others again <wink>.

> or you need a better box (I thought you had a 700+ MHz thingamabob)...

That was on a 866MHz P3, 256Mb RAM, Win98SE.  I've seen this for
approximately 10 years, though, on all sorts of boxes.

> On my box (being similarly vague), the time command shows no
> more than 0.04sec user time for the python command and no more
> than 0.01sec user time for the perl command (even after
> adding a \n to make them truly comparable ;-).

Like everything else, it varies by platform and configuration.  I'm not keen
to dig into the details on either of our boxes, though -- like I said, it's
been discussed on c.l.py many times already.  Last time it popped on
Python-Dev (via Greg Stein), Greg Ward reported these stats on the number of
system calls at startup, obtained via running truss/strace/par on assorted
Unix variants:

Total:
               Solaris     Linux    IRIX[1]
  Perl              88        85      70
  Python           425       316     257

Number of "open" calls:
               Solaris     Linux    IRIX
  Perl             16         10       9
  Python          107         71      48

Number of unsuccessful "open" calls:
               Solaris     Linux    IRIX
  Perl              6          1       3
  Python           77         49      32

Number of "mmap" calls:
               Solaris     Linux    IRIX
  Perl              25        25       1
  Python            36        24       1

Number of "brk" calls:
               Solaris     Linux    IRIX
  Perl               6        11      12
  Python            47        39      25


> Still, the machine seems to think that Python is slower than Perl
> at startup even though I can't tell...

Write a little shell loop, and count how *many* times you can start each in,
say, a grand total of 10 seconds (that's a crude model of what people who
claim to care about this are concerned about).  Then do it again adding "-S"
to your python line.  You may (or may not <0.5 wink>) discover something
interesting on your box.

> of-course-it-could-be-a-windows-/-linux-thing-jab-jab-ly y'rs,

Absolutely.  Python on Windows goes crawling thru the registry too, and is
*always* built from dynamic libraries (python.exe is under 24Kb on
Windows -- it's not like running that alone can accomplish much <wink>).

"startup"-covers-a-world-of-activities-all-by-itself-ly y'rs  - tim





More information about the Python-list mailing list