Python performance notes...

Aahz Maruch aahz at netcom.com
Thu May 25 16:12:17 CEST 2000


In article <392A2ED5.6A35B754 at san.rr.com>,
Courageous  <jkraska1 at san.rr.com> 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
f=open(sys.argv[1])
s=f.read()
f.close()
words=re.split(s,r'\s')
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 netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
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