Python / C: small runtime difference?

Martin Schneider martin.schneider at illusion-factory.de
Tue Sep 9 09:54:41 EDT 2003


Hi, Gerhard,

thanks for your answer :-)

Here's my python code:

for i in range(len(fileList)-1):
 for j in range(len(fileList)-i-1):
  if fileList[j+1] < fileList[j]:
   tmp = fileList[j]
   fileList[j] = fileList[j+1]
   fileList[j+1] = tmp

Of course I don't know what Python does here internally.

> It's best to have an array of pointers to structs. Then in
> your bubble-sort algorithm, only exchange the pointers, don't copy the
> structs themselves.

Okay - I'll try that :-)

> So if you make your C code as
> smart as Python automatically is <wink>, your C code should be a hell of
> a lot faster than your Python code :-)

Maybe :-) I'll let you know.

Thanks!

Martin






More information about the Python-list mailing list