Python startup seems slow... (NT)

Tim Peters tim_one at email.msn.com
Wed Jan 26 00:39:21 EST 2000


[Jason Taylor]
> Under NT, it seems that starting up python to process even
> a trivial script is pretty slow.

Under all installations of NT, or some specific one that you tried?  Don't
laugh <wink>.  One thing to watch out for is fragmentation under NT.  Get a
defrag utility (e.g., Diskkeeper Lite is free) and check that out.

> With the following python program, helloworld.py:
>
>   print "Hello World"
>
> it takes a second or more for "python helloworld.py" to execute
> on my machine.  It doesn't get any faster the second or third
> time around.
>
> Curious, I used the same program with Perl.  It had basically
> no delay.

One way in which Python differs is that part of Python is written in Python,
and so Python does more poking around on the disk (looking for Python files)
than Perl does at startup.  This involves filesystem stat calls, which
aren't speedy under Windows.  Alas, the people who know the most about this
are at the Python Conference now, so your timing is off.

After defragging your disks, a couple things to check out:

1. Python looks for and executes site.py at startup.  You can
   disable that by passing the -S switch.  Depending on what's
   in site.py, running it can consume an arbitrary amount of
   time.  Specifying -S saves significant startup time on my
   old P5-166 Win95 box -- which seems nevertheless faster
   than your NT box!

2. Python looks for and loads exception class definitions from
   exceptions.py.  You can disable that by passing the -X
   switch.  This is a Bad Idea (the -X switch will go away
   somdeday), but timing the difference with & without will
   at least shed some light.

Doing both of those speeds startup a lot for me -- but Perl startup is still
obviously quicker on my machine.

One other thing:  trim sys.path to the minimum.  This won't help startup,
but can save oodles once the app gets going.

And one final thing:  if python.exe is resolved later in your PATH than
perl.exe, it takes Windows that much longer to find it to begin with
(Windows isn't much quicker at finding things than Python is <wink>).
Fastest under Windows is to specify a full path (including the trailing
".exe").

the-death-of-a-thousand-cuts-ly y'rs  - tim






More information about the Python-list mailing list