forked from CyrusNuevoDia/CSV.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
63 lines (53 loc) · 1.26 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* jshint esversion: 6 */
let Benchmark = require('benchmark');
let fs = require("fs");
let CSV = require("./csv");
let Baby = require("babyparse");
let D3 = require("d3-dsv");
let csv = fs.readFileSync("./datasets/csv/marriage_census.csv", "utf8");
let json = JSON.parse(fs.readFileSync("./datasets/json/marriage_census.json", "utf8"));
let log = (event) => console.log(String(event.target));
let noop = () => {};
let opts = {
newline: "\n",
delimiter: ","
};
let inferredStreamOpts = {
step: noop
};
let streamOpts = {
newline: "\n",
delimiter: ",",
step: noop
};
let suite = new Benchmark.Suite();
suite.
// add("CSV.parse", () => {
// CSV.parse(csv, opts);
// }).
// add("CSV.parse, stream", () => {
// CSV.parse(csv, opts, noop);
// }).
add("D3.parse", () => {
D3.csvParseRows(csv);
}).
add("Baby.parse", () => {
Baby.parse(csv, opts);
}).
add("Baby.parse, stream", () => {
Baby.parse(csv, streamOpts);
}).
add("CSV.encode", () => {
CSV.encode(json, opts);
}).
add("CSV.encode, stream", () => {
CSV.encode(json, opts, noop);
}).
add("Baby.unparse", () => {
Baby.unparse(json, opts);
}).
add("Baby.unparse, stream", () => {
Baby.unparse(json, streamOpts);
}).
on("cycle", log).
run();