-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
100 lines (94 loc) · 2.27 KB
/
index.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// var csv=require('fast-csv')
// var csv=require('csv')
var csvtojson = require('csvtojson')
var csv = require('csv')
var fastCsv = require('fast-csv')
var csvParser = require('csv-parser')
var Papa = require('papaparse')
var csvFile = '1.csv'
var outputFile = "output.txt";
console.time("fast-csv")
testFastCsv(function () {
console.timeEnd("fast-csv")
console.time("csv")
testCsv(function () {
console.timeEnd("csv")
console.time("csvtojson")
testCsvToJson(function () {
console.timeEnd("csvtojson")
console.time("csv-parser")
testCsvParser(function () {
console.timeEnd("csv-parser")
console.time("papaparse")
testPapaParse(function () {
console.timeEnd("papaparse")
})
})
})
})
})
function testCsvToJson(cb) {
var fileName = "csvtojson-" + outputFile;
var ws = require('fs').createWriteStream(fileName)
csvtojson({
noheader: true
})
.fromFile(csvFile)
.on("csv", function (d) {
ws.write(d[0] + "\n")
})
.on("end", function () {
cb()
})
}
function testFastCsv(cb) {
var fileName = "fastcsv-" + outputFile;
var ws = require('fs').createWriteStream(fileName)
fastCsv
.fromPath(csvFile)
.on("data", function (d) {
ws.write(d[0] + "\n")
})
.on("end", function () {
cb()
})
}
function testCsv(cb) {
var fileName = "csv-" + outputFile;
var ws = require('fs').createWriteStream(fileName)
var rs = require('fs').createReadStream(csvFile)
var stream=csv.parse();
rs.pipe(stream)
.on("data",function(d){
ws.write(d[0] + "\n")
})
.on("end",function(){
cb();
})
}
function testCsvParser(cb) {
var fileName = "csvParser-" + outputFile;
var ws = require('fs').createWriteStream(fileName)
var rs = require('fs').createReadStream(csvFile)
var stream = csvParser();
rs.pipe(stream)
.on("data",function(d){
ws.write(d[0] + "\n")
})
.on("end",function(){
cb();
})
}
function testPapaParse(cb) {
var fileName = "papaParse-" + outputFile;
var ws = require('fs').createWriteStream(fileName)
var rs = require('fs').createReadStream(csvFile)
var stream = Papa.parse(Papa.NODE_STREAM_INPUT)
rs.pipe(stream)
.on("data",function(d){
ws.write(d[0] + "\n")
})
.on("end",function(){
cb();
})
}