All files / csv2json/bin benchmark.js

0% Statements 0/29
0% Branches 0/2
0% Functions 0/5
0% Lines 0/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                               
#!/usr/bin/env node
var path = process.argv[2];
var fs = require('fs');
if (!fs.existsSync(path)) {
  console.log("Run: benchmark [csvpath]");
  console.log("File not found: ", path);
  process.exit(1);
}
function testCSVLine(coreNum, checkType, cb){
  console.log("WorkerNum:", coreNum, "Check Type: ", checkType);
  var Converter = require("../libs/core/Converter");
  var rs = fs.createReadStream(path);
  var converter = new Converter({
    workerNum: coreNum,
    checkType: checkType,
    constructResult: false
    // fork:true
  });
  var totalLines = 0;
  var secLines = 0;
  converter.on("data", function() {
    totalLines++;
    secLines++;
  });
  converter.on("end", function() {
    clearInterval(timer);
    console.log("");
    var t = new Date() - start;
    console.log("Time elapsed: ", t, " ms");
    console.log("Total lines: " + totalLines);
    console.log("Average Speed: " + Math.round(totalLines / t * 1000) + " Lines / Sec");
    cb();
  });
  var timer = setInterval(function() {
    process.stdout.write("\r" + secLines + " CSV Lines/Sec");
    secLines = 0;
  }, 1000);
  var start = new Date();
 
  var stream = rs.pipe(converter);
}
 
// testCSVLine(1,false,false,function(){
  testCSVLine(4,true,function(){
 
  });
// });