From: Ed Sinjiashvili Date: 2001-09-19T16:17:47+09:00 Subject: [ruby-talk:21378] Path walking on windows Hi, I've created a little script that recurses through directories and yields all files to block. Here it is class Dir def walk (prefix = nil, &walker) e = self.entries e.delete "."; e.delete ".." if prefix e.collect! {|x| File.join(prefix, x) } end if block_given? e.each {|x| if File.directory? x then Dir.new(x).walk x, &walker end yield x } end nil end end Dir.new(".").walk {|p| puts p} But when I tried to run it on Win98 I was amazed how slow it is. I began to browse the list archive to find a way to optimize the script (remembering how hash script was optimized) and found out that I actually could use find.rb from standard library. require "find" Find.find(".") {|p| puts p} I tried it - but it was even slower than my version. Well, I decided to give python a try. import os def visitor (arg, dirname, files): for i in range(0, len(files)): if not os.path.isdir(files[i]): print (dirname + "\\" + files[i]) os.path.walk (".", visitor, None) Python script was magnitude times faster. Some figures (made with simple bat file - don't know how to measure on win) Dir.walk script - 40 sec Find.find script - 45 sec python script - 5 sec I also tried all three scripts on Linux machine and ruby versions worked just fine - they were faster than python one. All three scripts ran less than 2 sec. I presume that this discrepancy is due to reiserfs vs fat32 issues. The question is why ruby scripts are losing so much against python on windoze? I'd be happy to hear any comments from you. BTW, I've tested ruby-1.6.2 on win98, ruby-1.6.2 on Mandrake 7 and python 2.1 on both win98 and mandrake. -- Ed Sinjiashvili