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

Hans Nowak wurmy at earthlink.net
Fri Aug 9 01:16:29 EDT 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.

I'm not sure that Python is closer to C++ than Ruby is, especially not 
syntax-wise...

> 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! 

I don't know that os.path.walk is slow. What exactly are you doing in each 
directory? Maybe the way you are searching for file extensions is inefficient, 
for example. Please post some example code.

Of course, it's also possible that Ruby is intrinsically faster than Python 
here, but let's not assume that for now. :-)

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/




More information about the Python-list mailing list