From: nobu.nokada@... Date: 2004-07-15T20:37:22+09:00 Subject: Re: my ruby code won't go as fast as my perl code Hi, At Thu, 15 Jul 2004 15:07:18 +0900, Dave Burt wrote in [ruby-talk:106480]: > I realise I'm doing this a perlish way, but my question is, is it possible > to do this operation in Ruby in a time more comparable to what the Perl > version's getting? (That's about 4 seconds; my Ruby code runs in about 17 > seconds over the same data set, which is far smaller than the production > data set.) Which version of ruby do you use? > Dir.open(dir).each do |file| > next if file[0] == ?. # skip dotfiles > reading = false > File.open(dir + '/' + file).each_line do |line| > reading ||= (date_regex =~ line && > (($3>='87'?'19':'20')+$3+mm[$2]+$1+$4+$5+$6 >= start_date)) > a << line if reading > end > end You open files but never close, this may cause too frequent GC. IO.foreach(dir + '/' + file) do |line| if reading a << line else reading = (date_regex =~ line && (($3>='87'?'19':'20')+$3+mm[$2]+$1+$4+$5+$6 >= start_date)) end end -- Nobu Nakada