Why is Python so slow ?- revisited.

William Dandreta wjdandreta at worldnet.att.net
Mon Jun 19 21:30:19 EDT 2000


Hi all,

I want to thank everyone who contributed to this thread, it has helped me
understand Python a little better.

All my thoughts on what was causing my Python script to run slow are false.

There is no speed penalty for comments.

There is no speed penalty for DOC strings.

There is no speed penalty for function calls. (At least in this case)

My error was that I did the following:

from strop import joinfields, splitfields
from string import replace

I erroneously assumed that replace would use the joinfields, splitfields
from strop, but it really used the joinfields, splitfields from string which
are very slow.

Bill
William Dandreta wrote in message ...
>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