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

Roman Suzi rnd at onego.ru
Fri Aug 9 00:44:49 EDT 2002


On Fri, 9 Aug 2002, Steven Atkinson wrote:

>I'm trying to settle on Ruby or Python as my scripting language of choice.
>There are some features of Ruby that I like, but I lean toward Python since
>by day I'm a C++ programmer and Python seems more natural to me.
>Unfortunately, in my first side by side test I discovered a _huge_
>performance difference (at least for what I wanted to do). I need a simple
>program that can clean out some tool generated source code. I'm recursively
>searching 100's (probably close to or slightly over a 1000) directories
>searching for certain file extensions (*_i.c, *_p.c,*.thi, *.thl) and then
>removing them. The Ruby version runs in about 20-30 seconds. The Python
>version takes 2-3 minutes! My feeling is that it's probably just the
>os.path.walk library routine is slow (only on NT, haven't tried on Linux.
>Maybe that's a good sanity check.). So before I dig into the code to
>determine why it's so slow I'd like to know if others experience slowness
>with Python overall, just the os.path.walk routine, only the NT version.
>
>I'll probably need to do lots of directory searching in future scripts, so
>I'd like that to be reasonably fast. Granted I could write my own extension,
>or maybe call the Win32 functions directly since the code does not need to
>be portable, but I'd rather not do that.

What about using glob module?

For example:

>>> glob.glob("*/*.c")
['bin/splitmus.c', 'bin/splitmuss.c', 'bin/wavf.c']

(there could be more "*/"-s, if you like)

>TIA

Sincerely yours, Roman Suzi
-- 
rnd at onego.ru =\= My AI powered by Linux RedHat 7.2





More information about the Python-list mailing list