On Oct 28, 2005, at 10:06 PM, James Edward Gray II wrote:

> Here's the hyper-optimized version with an example of how he uses  
> it (translated from Perl to Ruby by me):

This certainly seems promising, at least as a starting point:

Neo:~/Desktop$ cat bm_csv.rb
#!/usr/local/bin/ruby -w

require "csv"
require "benchmark"

def parse_csv( line )
   results = Array.new
   line.scan(/\G(?:^|,)(?:"((?>[^"]*)(?>""[^"]*)*)"|([^",]*))/) do
     if $1.nil?
       results << $2
     else
       results << $1.gsub('""', '"')
     end
   end
   results
end

DATA  = %Q{Ten Thousand,10000, 2710 ,,"10,000","It's ""10 Grand"",  
baby",10K}
TESTS = 50000

Benchmark.bm do |timings|
   timings.report("CSV") { TESTS.times { CSV.parse_line(DATA) } }
   timings.report("Regexp") { TESTS.times { parse_csv(DATA) } }
end
Neo:~/Desktop$ ruby bm_csv.rb
       user     system      total        real
CSV 18.570000   0.060000  18.630000 ( 18.675331)
Regexp  2.700000   0.010000   2.710000 (  2.726666)

James Edward Gray II