Python performance notes...

Aahz Maruch aahz at
Thu May 25 10:12:17 EDT 2000

In article <392A2ED5.6A35B754 at>,
Courageous  <jkraska1 at> wrote:
>I did a simple for loop and tested it, trying a variety of length
>loops. It took a bit of time to get this right, as for smaller
>loops, the test was biased by the relative high cost of function
>invocation. When it settled out, a for-loop in python is about 100
>times slower in python than the equivalent in ANSI C. Irrespective of
>function invocation overhead, the decision to go native pays off almost
>immediately, with time differences in python versus native code being
>noticeable with as low as 100,000 simple iterations.

So?  What's your point?  Try writing the following code in C:

import re,sys
uniqWords = {}
for word in words:
  uniqWords[word] = 1
for word in uniqWords.keys():
  print word

How long did it take you?  Did it run as fast as the Python code?  Was
the overhead of the two loops here really a significant factor?
                      --- Aahz (Copyright 2000 by aahz at

Androgynous poly kinky vanilla queer het    <*>
Hugs and backrubs -- I break Rule 6

"Yes, but would you kick any of them out of bed?"
"That depends: do we have to do anything with them in the bed, or
are they just in the bed?" -- AM/SJM

More information about the Python-list mailing list