Python vs. Ruby (and os.path.walk)

Kristian Ovaska kristian.ovaska at
Mon Aug 12 09:05:44 CEST 2002

"Steven Atkinson" <sja at>:
>Ran again. Same results. Took out all IO from the Python script and ran it
>alone :15. Wow! Took the IO out of Ruby: :13. Humm. Put the IO back in both
>and ran in parrellel. Python :18, Ruby :14. Other runs would have different
>times, but Ruby would generally finish a tad faster. Tried to put the code
>back as orignally designed and could never get back to 2-3 minutes.

Getting directory listings is almost completely an OS issue. I wrote a
Python script that calculates the size of a directory tree, and found
performance bad on large trees. I wrote a C version - and it was
slower than Python!

On Windows 98/Me, listdir is not very fast. I don't know about
NT/2000. I have an old Pascal version that calls DOS interrupts
directly, and it is 10 times faster than any method I have found on
Windows. Just not very portable, and it doesn't understand long
filenames, of course.

And remember that cache will play a role when you do benchmarks. If
you get 10 seconds one day, it might be 60 seconds the next day when
you run it the first time.

Kristian Ovaska <kristian.ovaska at>

More information about the Python-list mailing list