Why is Python so slow ?- revisited.

William Dandreta wjdandreta at worldnet.att.net
Sun Jun 18 23:22:06 EDT 2000


Hi Christian,

Christian Tismer wrote in message
<394D6579.8B2FF840 at appliedbiometrics.com>...

>Are you sure that you are talking about Python 1.2 ???
>Let me assume it is 1.5.2 - ok?


It is Python 1.2 because the later versions will not run on my machine.

>1) both joinfields and splitfields are deprecated. Please use
>   split and join instead.
>2) Is the split(join(...)) pattern necessary here? If the pattern
>   is a simple string, then you might be reasonably faster with
>   a single string.replace(str, oldstr, newstr) call.


I tried split and join first but the versions in strop have undocumented
parameters so I switched to splitfields, joinfields. Also, if you check the
source for string.py, split calls splitfields and join calls joinfields.

the replace function in string.py is simply

def replace (...

   """
   DOC String

  """

  return joinfields(splitfields(...)...)


>The time spent in comment lines is very small,and it is reasonably
>smaller if you use Stackless Python. Anyway, if you are concerned
>about multi-line comments, then try this out:
>Put a """ line in front of a longer couple of comments,
>and end it the same way.
>I should wonder if execution time would change reasonably.


The """ syntax would seem to be slower than putting # at the begining of
everyline because with # it only needs to test the first character of the
line, if it's # it can skip the rest of the line. But with """, it needs to
check every character after until it finds the matching """.


>If you move all of your comment text into the first line of your
>funcion, then it will become the DOC string, and it will cost
>you not a single cycle.

What we are talking about here is the DOC string in the Python source file
string.py. I will test it with your suggestions and see what happens.

Bill





































More information about the Python-list mailing list