From: ser@... (Sean Russell) Date: 2004-07-16T01:32:31+09:00 Subject: Re: my ruby code won't go as fast as my perl code #!ruby require 'csv' require 'parsedate' start_date = Time.local(*ParseDate.parsedate('1-APR-03 00:00:00')) dir = "data" a = [] t = Time.new Dir.entries( dir ).each do |f| fpath = File.join( dir, f ) if FileTest.file?( fpath ) CSV.parse( fpath ) do |row| a << row if Time.local(*ParseDate.parsedate(row[0].to_s)) >= start_date end end end t = Time.new - t; puts "Read #{a.size} lines in #{t} seconds"; # It would be more efficient to output the data in the other loop, but I # assume you're wanting to do some additional processing to it here. t = Time.new File.open( "ruby.out", "w" ) do |outfile| CSV::Writer.generate(outfile) do |csv| a.each {|r| csv.add_row r } end end t = Time.new - t; puts "Wrote #{a.size} lines in #{t} seconds"