From: Kikutani Makoto Date: 1998-05-20T11:40:04+09:00 Subject: [ruby-list:8021] Re: Dir.open order みなさま回答ありがとうございます。 1000以上メッセージがあるフォルダで試してみました。 まつもとさんの方法 ------------------------- Dir.chdir("/home/kikutani/Mail/outbox/cur") a = nil Dir.open(".") do |d| a = d.collect{|f| [f, File.mtime(f)]}.sort{|a,b| a[1] <=> b[1]} end a.each{|f| print f, "\n" } ------------------------- 0.60s user 0.61s system 100% cpu 1.209 to$ わたなべひろふみさんの方法 ------------------------- a = Dir["/home/kikutani/Mail/outbox/cur/*"].sort {|a,b| File.stat(a).mtime <=> $ a.each{|f| print f, File.mtime(f), "\n" } ------------------------- 4.17s user 6.61s system 100% cpu 10.769 t$ わたなべてつやさんの方法 ------------------------- Dir.chdir("/home/kikutani/Mail/outbox/cur") dir = Dir.open(".") for file in dir.sort {|a, b| File.mtime(a) <=> File.mtime(b)} print file, File.mtime(file), "\n" end dir.close ------------------------- 4.11s user 7.01s system 99% cpu 11.177 to$ というわけで、結果は同じなんですが、まつもとさんのがやけに速い秘密は? collectを使うというのはシロートは思いつきませんね。 -- 人生谷あり谷あり [Copyright (C) by Dr. Moro] 菊谷 誠(Kikutani Makoto) kikutani@gol.com kikutani@debian.or.jp (Linux関係のみ)