Python startup performance ?

Jeremy Hylton jeremy at cnri.reston.va.us
Thu Oct 21 14:04:57 EDT 1999


>>>>> "AS" == Arun Sharma <adsharma at home.com.nospam> writes:

  AS> Not a big deal - but would be helpful when executing a large
  AS> number of python scripts over and over again.

Here's the same stuff on my (aging) Sparc Ultra2.  (I'm averaging the
user and sys times over 20 runs and disregarding the real "wallclock"
time.)

time -p perl -e 'print "hello world\n"'
user 0.011
sys 0.0135
total 0.0245

time -p python -c 'print "hello world\n"'
user 0.065
sys 0.051
total 0.116

So I'm seeing close to the factor of four that Bjorn reported.
 
I thought it was interesting to see what effect the -S and -X options
had on startup performance.

The -X option disables class based exceptions.  Since the exceptions
are defined by Python source code that needs to be executed when the
interpreter starts.  It has a small effect.

time -p python -X -c 'print "hello world\n"'
user 0.052
sys 0.0405
total 0.0925

I'm less clear on what the -S option does, but I assume it depends in
large part of what your site's Python configuration looks like.  It is
reading a bunch of .pth files that affect that path and looking for a
sitecustomize module.  I've got 4 .pth files for my installation.

time -p python -S -c 'print "hello world\n"'
user 0.0305
sys 0.0205
total 0.051

The two together bring Python startup time much closer to Perl startup
time. 

time -p python -S -X -c 'print "hello world\n"'
user 0.0175
sys 0.0205
total 0.038

Using this incantation, Python is only 50% slower than Perl.  So all
the extra time is going to nifty features like class-based exceptions
and support for customizing the local Python installation.

Jeremy




More information about the Python-list mailing list