forked from CyrusOfEden/CSV.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.js
71 lines (58 loc) · 1.58 KB
/
bench.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
63
64
65
66
67
68
69
70
71
var Benchmark = require('benchmark'),
CSV = require("./csv"),
fs = require("fs"),
csv, json;
Parse = new Benchmark.Suite("Parse"),
ParseHeader = new Benchmark.Suite("Parse, Header"),
Encode = new Benchmark.Suite("Encode"),
EncodeHeader = new Benchmark.Suite("Encode, Header"),
options = {
normal: { line: "\n" },
header: { line: "\n", header: true },
optimize: { line: "\n", optimize: true }
},
noop = function() {};
Parse.
add("CSV#parse", function() {
CSV.parse(csv, options.normal);
}).
add("CSV#forEach", function() {
CSV.forEach(csv, options.normal, noop);
});
ParseHeader.
add("CSV#parse", function() {
CSV.parse(csv, options.header);
}).
add("CSV#forEach", function() {
CSV.forEach(csv, options.header, noop);
});
Encode.
add("CSV#encode", function() {
CSV.encode(json, options.normal);
}).
add("CSV#forEach", function() {
CSV.forEach(json, options.normal, noop);
});
EncodeHeader.
add("CSV#encode", function() {
CSV.encode(json, options.header);
}).
add("CSV#forEach", function() {
CSV.forEach(json, options.header, noop);
});
function log(suite) {
var result;
suite.run();
suite.forEach(function(bench) {
result = suite.name + ": " + bench.toString();
console.log(result);
});
}
fs.readFile("./datasets/csv/marriage_census.csv", 'utf8', function(err, res) {
csv = res;
[Parse, ParseHeader].forEach(log);
});
fs.readFile("./datasets/json/marriage_census.json", 'utf8', function(err, res) {
json = JSON.parse(res);
[Encode, EncodeHeader].forEach(log);
});