Why is Python so slow ?- revisited.

William Dandreta wjdandreta at worldnet.att.net
Sun Jun 18 19:32:55 EDT 2000


Let me preface my remarks with:

--I am using the Python 1.2 binary for DOS with the Python 1.5.2 library
which causes some problems. I avioded some problems by importing functions
directly from strop instead of string. Replace is not in strop so I used the
one in string but I had to comment out (put an octothorpe at the start of
each line) the function's descriptive string to get it to work.--

A while ago I posted a message called Why is Python so slow? At that time
this Python script took 90 minutes to run. By making some relatively minor
changes, I was able to reduced the time to 6 minutes.

The biggest improvement came (about a factor of 6) when I changed the
replace(x,y) function in string with
joinfields(splitfields(x,y),''). Considering that this is exactly what the
replace function in string does, I was quite surprised at the results.
Essentially I reduced 3 nested function calls to 2.

The only thing that makes sense to me is that Python is spending 85% of the
time processing the comment lines and 15% of the time doing useful work.
There is a string.pyc so I would have assumed that it would not contain any
comments or descriptive strings but apparently that's not true.

I am not very familiar with interpretive languages, Python is the first one
I have used, but it seems that comments can cause a serious perfomance hit
because they have to be processed along with the code.

Bill





More information about the Python-list mailing list