|
|
|
|
|
by deno
3581 days ago
|
|
Better than node.js import * as csv from 'csv-parse';
import * as fs from 'fs';
type Line = [string,string,string,string,string,string];
const parser = new csv.Parser({});
parser.on('data', (line: Line) => {
if (line[0] === '42') {
console.dir(line);
}
});
fs.createReadStream('mock_data.csv').pipe(parser);
$ /usr/bin/time node parse_csv.js
43.61user 0.85system 0:45.61elapsed 97%CPU (0avgtext+0avgdata 60076maxresident)k
$ node --version
v6.4.0
Edit: Using fast-csv 24.28user 0.20system 0:24.58elapsed 99%CPU (0avgtext+0avgdata 91780maxresident)k
|
|
https://www.npmjs.com/package/csv-parser
Edit: `fast-csv` seems to be using a lot of `RegExp`s on each iteration which can't be that fast compared to csv-parser which seems to simply go over each symbol (state machine?).