📜 ⬆️ ⬇️

Ruby & Ccsv. FasterCSV is not so faster

The challenge was to pull the info from a large csv file (50 MB).
I always used FasterCSV , but since it opened this file for more than a minute, I began searching for the present faster.
Without the help of Google has not done.
Ccsv is fast and easy to work with .csv files.

Ccsv is implemented in C and under Ruby. As you can see, the difference in runtime is big:

user system total real
6.050000 0.460000 6.510000 ( 6.868348) - ccsv
60.540000 5.350000 65.890000 ( 68.840146) - fastercsv
17.400000 0.430000 17.830000 ( 18.786114) - split (file.each_line {|row| columns = row.split})


There were rakes. Ccsv comes as a gem and by default has a separator ','.
Had pens to add it as a parameter:

static VALUE foreach(VALUE self, VALUE filename, VALUE delimetr) {...}

void
Init_ccsv()
{
rb_cC = rb_define_class("Ccsv", rb_cObject);
rb_define_singleton_method(rb_cC, "foreach", foreach, 2);
}


Example of use:
Ccsv.foreach(filename, ",\n") { |row| row[0] }

The original library is here
')

Source: https://habr.com/ru/post/68950/


All Articles