Skip to content

Commit

Permalink
Merge pull request #74 from doug-martin/master
Browse files Browse the repository at this point in the history
v0.5.3
  • Loading branch information
doug-martin committed Oct 21, 2014
2 parents 8cf7e3e + 0f19195 commit 4bad879
Show file tree
Hide file tree
Showing 15 changed files with 21,336 additions and 901,247 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- "0.10"
- "0.11"
before_script:
- npm install -g grunt-cli
13 changes: 13 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-exec');

grunt.registerTask("benchmark", "run benchmarks", function () {
var done = this.async();
require("./benchmark/benchmark")(function (err) {
if (err) {
grunt.log.error(err.stack);
done(false)
} else {
grunt.log.ok("Done running benchmarks");
done();
}
});
});

};
7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.5.3

* Fixed issues with `v0.11` stream implementation [#73](https://github.com/C2FO/fast-csv/issues/73)
* Fixed issues with `pause/resume` and data events in `v0.10` [#69](https://github.com/C2FO/fast-csv/issues/69)
* Fixed the double invoking of done callback when parsing files [#68](https://github.com/C2FO/fast-csv/issues/68)
* Refactored tests

# v0.5.2

* Fixed issue with `writeToString` and `writeToPath` examples [#64](https://github.com/C2FO/fast-csv/issues/64)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ This accepted a readable stream to parse data from.
```javascript
var stream = fs.createReadStream("my.csv");

csv()
csv
.fromStream(stream)
.on("data", function(data){
console.log(data);
Expand All @@ -169,7 +169,7 @@ cause change each row to an object rather than an array.
```javascript
var stream = fs.createReadStream("my.csv");

csv()
csv
.fromStream(stream, {headers : true})
.on("data", function(data){
console.log(data);
Expand Down
900,002 changes: 1 addition & 900,001 deletions benchmark/assets/100000.csv

Large diffs are not rendered by default.

93 changes: 61 additions & 32 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
var fastCsv = require("../lib"),
csv = require("csv"),
path = require("path"),
fs = require("fs"),
COUNT = 10000000,
TEST_FILE = path.resolve(__dirname, "./assets/" + COUNT + ".csv");
fs = require("fs");


function camelize(str) {
Expand All @@ -12,10 +10,11 @@ function camelize(str) {
});
}

function benchmarkFastCsv(done) {
var count = 0;
function benchmarkFastCsv(num, done) {
var count = 0,
file = path.resolve(__dirname, "./assets/" + num + ".csv");
fastCsv
.fromPath(TEST_FILE, {headers: true})
.fromPath(file, {headers: true})
.transform(function (data) {
var ret = {};
["first_name", "last_name", "email_address"].forEach(function (prop) {
Expand All @@ -28,8 +27,8 @@ function benchmarkFastCsv(done) {
count++;
})
.on("end", function (count) {
if (count !== COUNT) {
done(new Error("Error expected " + COUNT + " got " + count));
if (count !== num) {
done(new Error("Error expected " + num + " got " + count));
} else {
done();
}
Expand All @@ -40,9 +39,10 @@ function benchmarkFastCsv(done) {

}

function benchmarkCsv(done) {
var count = 0;
fs.createReadStream(TEST_FILE)
function benchmarkCsv(num, done) {
var count = 0,
file = path.resolve(__dirname, "./assets/" + num + ".csv");
fs.createReadStream(file)
.pipe(csv.parse({columns: true}))
.pipe(csv.transform(function (data) {
var ret = {};
Expand All @@ -56,8 +56,8 @@ function benchmarkCsv(done) {
count++;
})
.on('end', function () {
if (count !== COUNT) {
done(new Error("Error expected " + COUNT + " got " + count));
if (count !== num) {
done(new Error("Error expected " + num + " got " + count));
} else {
done();
}
Expand All @@ -67,26 +67,26 @@ function benchmarkCsv(done) {
});
}

function benchmark(title, m, done) {
function benchmark(title, num, m, done) {
var start = new Date(), runStart = start;
m(function (err) {
m(num, function (err) {
if (err) {
done(err);
} else {
console.log("%s: RUN 1 %dms", title, (new Date() - runStart));
console.log("%s: RUN(%d lines) 1 %dms", title, num, (new Date() - runStart));
runStart = new Date();
m(function (err) {
m(num, function (err) {
if (err) {
done(err);
} else {
console.log("%s: RUN 2 %dms", title, (new Date() - runStart));
console.log("%s: RUN(%d lines) 2 %dms", title, num, (new Date() - runStart));
runStart = new Date();
m(function (err) {
m(num, function (err) {
if (err) {
done(err);
} else {
console.log("%s: RUN 3 %dms", title, (new Date() - runStart));
console.log("%s: 3xAVG %dms", title, (new Date() - start) / 3);
console.log("%s: RUN(%d lines) 3 %dms", title, num, (new Date() - runStart));
console.log("%s: 3xAVG for %d lines %dms", title, num, (new Date() - start) / 3);
done();
}

Expand All @@ -97,14 +97,43 @@ function benchmark(title, m, done) {
});
}

benchmark('fast-csv', benchmarkFastCsv, function (err) {
if (err) {
console.log(err.stack);
} else {
benchmark('csv', benchmarkCsv, function (err) {
if (err) {
console.log(err.stack);
}
});
}
});
function runBenchmarks(num, cb) {
console.log("RUNNING %d.csv benchmarks", num);
benchmark('fast-csv', num, benchmarkFastCsv, function (err) {
if (err) {
cb(err);
} else {
benchmark('csv', num, benchmarkCsv, function (err) {
if (err) {
cb(err);
} else {
console.log("");
cb();
}
});
}
});
}

module.exports = function benchmarks(cb) {
runBenchmarks(20000, function (err) {
if (err) {
cb(err);
} else {
runBenchmarks(50000, function (err) {
if (err) {
cb(err);
} else {
runBenchmarks(100000, function (err) {
if (err) {
cb(err);
} else {
cb(null);
}
});
}
});
}
});
};

5 changes: 4 additions & 1 deletion benchmark/createData.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ while (++i < l) {
lines.push(lineOptions[i % lineOptionsLength]);
}

console.log("writing %d lines to %d.csv", l, l);
fastCsv
.writeToPath(path.resolve(__dirname, "./assets/20000.csv"), lines)
.on('finish', function () {
Expand All @@ -28,21 +29,23 @@ fastCsv
lines.push(lineOptions[i % lineOptionsLength]);
}

console.log("writing %d lines to %d.csv", l - 1, l - 1);
fastCsv
.writeToPath(path.resolve(__dirname, "./assets/50000.csv"), lines)
.on('finish', function () {
l = 100002;
while (++i < l) {
lines.push(lineOptions[i % lineOptionsLength]);
}

console.log("writing %d lines to %d.csv", l - 2, l - 2);
fastCsv
.writeToPath(path.resolve(__dirname, "./assets/100000.csv"), lines)
.on('finish', function () {
l = 1000003;
while (++i < l) {
lines.push(lineOptions[i % lineOptionsLength]);
}
console.log("writing %d lines to %d.csv", l - 3, l - 3);
fastCsv.writeToPath(path.resolve(__dirname, "./assets/1000000.csv"), lines)
.on("finish", function () {
process.exit();
Expand Down
7 changes: 7 additions & 0 deletions docs/History.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@



<h1>v0.5.3</h1>
<ul>
<li>Fixed issues with <code>v0.11</code> stream implementation <a href="https://github.com/C2FO/fast-csv/issues/73">#73</a></li>
<li>Fixed issues with <code>pause/resume</code> and data events in <code>v0.10</code> <a href="https://github.com/C2FO/fast-csv/issues/69">#69</a></li>
<li>Fixed the double invoking of done callback when parsing files <a href="https://github.com/C2FO/fast-csv/issues/68">#68</a></li>
<li>Refactored tests</li>
</ul>
<h1>v0.5.2</h1>
<ul>
<li>Fixed issue with <code>writeToString</code> and <code>writeToPath</code> examples <a href="https://github.com/C2FO/fast-csv/issues/64">#64</a></li>
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ <h3>Parsing</h3>
<p>This accepted a readable stream to parse data from.</p>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">var stream = fs.createReadStream(&quot;my.csv&quot;);

csv()
csv
.fromStream(stream)
.on(&quot;data&quot;, function(data){
console.log(data);
Expand All @@ -317,7 +317,7 @@ <h3>Parsing</h3>
cause change each row to an object rather than an array.</p>
<pre class='prettyprint linenums lang-js'><code class="lang-javascript">var stream = fs.createReadStream(&quot;my.csv&quot;);

csv()
csv
.fromStream(stream, {headers : true})
.on(&quot;data&quot;, function(data){
console.log(data);
Expand Down
Loading

0 comments on commit 4bad879

Please sign in to comment.