From: akuri Date: 2009-03-01T21:01:02+09:00 Subject: [ruby-list:45896] 1.9.1におけるファイルアクセス速度 はじめまして。akuriと申します。私は、テキストファイルを読み込んで編集し、 またテキストファイルに書き込むような処理をRubyで行っています。 (プログラミングは、あまり詳しくありません) Ruby1.8.6から1.9.1への移行を検討しており、現在使用しているプログラムを、 1.9.1で動かして見ましたが、処理速度が遅くなります。 環境は、Windows XP HomeEdition SP3、Intel Celeron 1.7GHzです。 profileをとっても、いまいち理解できませんでしたが、何となくファイルから の読み込み、書き込みが遅くなっているような気がします。 そこで、以下のプログラムを、Rubyの複数バージョンで実行してみました。 t_o = Time.new str = "abcdef\nghijklmno\npqrstu\nvwxyz\n0123456879" puts "print string to file" t = Time.new open("test.txt","w") do |file| 1.upto(500000) do |n| file.print str,"\n" end end print Time.new-t,"\n\n" puts "read from file ,and regexp match ,and print to file" t = Time.new reg = Regexp.new("abcdef|nvwxyz|5687") open("test2.txt","w") do |file2| open("test.txt") do |file3| file3.each_line do |line| line =~ reg file2.print line end end end print Time.new-t,"\n\n" File.unlink("test.txt") File.unlink("test2.txt") puts "Finished,press any key" key = gets 実行結果は、以下の通りです。 ruby1.8.6 p114 (OneClickRubyInstaller 1.8.6-26 Final Release) print string to file 3.328 read from file ,and regexp match ,and print to file 32.5 ruby1.9.1 p0 (http://www.garbagecollect.jp/ruby/mswin32/ja/ より) print string to file 10.34375 read from file ,and regexp match ,and print to file 88.328125 そこで、以下の2点について教えてください。 (1)1.9.1において、ファイルへの読み込みや書き込みをする場合、処理速度  を早くするような特別な記述方法があれば、教えてください。 (2)このような速度差は、仕様上当然のことであり、今後とも改善は見込まれ  ないでしょうか? 数GBあるファイルを処理するため、今後、1.9.1の利用を前提とするか、 1.8.6を使い続けるか、迷っています。