Jul 3, 2013

Perl: parse complex CSV fast!!!

I've been searching for the fastes way to parse huge csv file (between 2GB and 6 GB)
I don't have a simple csv file like:

first,second,third,

I need to parse a complex csv file like:

first,"second","my row , my column",text,number,"foo, foo",12312312312

where the fields are

  • first
  • "second"
  • "my row , my column"
  • text,number
  • "foo, foo"
  • 12312312312


So using the fast function built-in perl split using the , char as delimiter is not making the job easier.

I've tryed different CSV parsers modules from cpan, test were made in the same csv file (5,6GB of text) some benchmarks:

CSV_PP link
$ time test.pl quarter
real 6m5.302s
user 5m38.423s
sys 0m22.843s

Acme_CSV link
$ time test.pl quarter
real 15m32.683s
user 15m12.215s
sys 0m17.239s

CSV_XS link
$ time test.pl quarter
real 6m5.302s
user 5m38.423s
sys 0m22.843s

Conclusion: CSV_XS have the best performances for the test I made.
Hope that helps!

No comments:

Post a Comment