Skip to content

Commit

Permalink
Merge pull request #6 from tschaub/benchmarks
Browse files Browse the repository at this point in the history
Add some benchmarks.
  • Loading branch information
tschaub committed Feb 4, 2014
2 parents 5577aca + 33f7d95 commit 61a2c84
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 2 deletions.
25 changes: 25 additions & 0 deletions benchmarks/read-integration-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var assert = require('assert');
var fs = require('fs');

var mock = require('..');


/**
* Timed test. This includes the mock setup and teardown as part of the overall
* test time.
* @param {function(Error)} done Callback.
*/
exports.test = function(done) {
mock({
'foo-mock.txt': 'foo'
});

fs.readFile('foo-mock.txt', 'utf8', function(err, str) {
assert.ifError(err);
assert.equal(str, 'foo');

mock.restore();
done();
});

};
28 changes: 28 additions & 0 deletions benchmarks/read-integration-real.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var assert = require('assert');
var fs = require('fs');
var path = require('path');

var rimraf = require('rimraf');

var tmpPath = '.tmp';


/**
* Timed test. This includes the setup and teardown as part of the overall
* test time.
* @param {function(Error)} done Callback.
*/
exports.test = function(done) {
fs.mkdir(tmpPath, function(mkdirErr) {
assert.ifError(mkdirErr);
var tmpFile = path.join(tmpPath, 'foo-real.txt');
fs.writeFile(tmpFile, 'foo', function(writeErr) {
assert.ifError(writeErr);
fs.readFile(tmpFile, 'utf8', function(readErr, str) {
assert.ifError(readErr);
assert.equal(str, 'foo');
rimraf(tmpPath, done);
});
});
});
};
35 changes: 35 additions & 0 deletions benchmarks/read-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var assert = require('assert');
var fs = require('fs');

var mock = require('..');


/**
* Test setup. Not timed.
*/
exports.beforeEach = function() {
mock({
'foo-mock.txt': 'foo'
});
};


/**
* Timed test.
* @param {function(Error)} done Callback.
*/
exports.test = function(done) {
fs.readFile('foo-mock.txt', 'utf8', function(err, str) {
assert.ifError(err);
assert.equal(str, 'foo');
done();
});
};


/**
* Test teardown. Not timed.
*/
exports.afterEach = function() {
mock.restore();
};
43 changes: 43 additions & 0 deletions benchmarks/read-real.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var assert = require('assert');
var fs = require('fs');
var path = require('path');

var rimraf = require('rimraf');

var tmpPath = '.tmp';


/**
* Test setup. Not timed.
* @param {function(Error)} done Callback.
*/
exports.beforeEach = function(done) {
fs.mkdir(tmpPath, function(err) {
if (err) {
return done(err);
}
fs.writeFile(path.join(tmpPath, 'foo-real.txt'), 'foo', done);
});
};


/**
* Timed test.
* @param {function(Error)} done Callback.
*/
exports.test = function(done) {
fs.readFile(path.join(tmpPath, 'foo-real.txt'), 'utf8', function(err, str) {
assert.ifError(err);
assert.equal(str, 'foo');
done();
});
};


/**
* Test teardown. Not timed.
* @param {function(Error)} done Callback.
*/
exports.afterEach = function(done) {
rimraf(tmpPath, done);
};
22 changes: 22 additions & 0 deletions benchmarks/write-integration-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var assert = require('assert');
var fs = require('fs');

var mock = require('..');


/**
* Timed test. This includes the mock setup and teardown as part of the overall
* test time.
* @param {function(Error)} done Callback.
*/
exports.test = function(done) {
mock();

fs.writeFile('foo-mock.txt', 'foo', function(err) {
assert.ifError(err);

mock.restore();
done();
});

};
23 changes: 23 additions & 0 deletions benchmarks/write-integration-real.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var assert = require('assert');
var fs = require('fs');
var path = require('path');

var rimraf = require('rimraf');

var tmpPath = '.tmp';


/**
* Timed test. This includes the setup and teardown as part of the overall
* test time.
* @param {function(Error)} done Callback.
*/
exports.test = function(done) {
fs.mkdir(tmpPath, function(mkdirErr) {
assert.ifError(mkdirErr);
fs.writeFile(path.join(tmpPath, 'foo-real.txt'), 'foo', function(err) {
assert.ifError(err);
rimraf(tmpPath, done);
});
});
};
29 changes: 29 additions & 0 deletions benchmarks/write-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var fs = require('fs');
var path = require('path');

var mock = require('..');


/**
* Test setup. Not timed.
*/
exports.beforeEach = function() {
mock();
};


/**
* Timed test.
* @param {function(Error)} done Callback.
*/
exports.test = function(done) {
fs.writeFile('foo-mock.txt', 'foo', done);
};


/**
* Test teardown. Not timed.
*/
exports.afterEach = function() {
mock.restore();
};
33 changes: 33 additions & 0 deletions benchmarks/write-real.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var fs = require('fs');
var path = require('path');

var rimraf = require('rimraf');

var tmpPath = '.tmp';


/**
* Test setup. Not timed.
* @param {function(Error)} done Callback.
*/
exports.beforeEach = function(done) {
fs.mkdir(tmpPath, done);
};


/**
* Timed test.
* @param {function(Error)} done Callback.
*/
exports.test = function(done) {
fs.writeFile(path.join(tmpPath, 'foo-real.txt'), 'foo', done);
};


/**
* Test teardown. Not timed.
* @param {function(Error)} done Callback.
*/
exports.afterEach = function(done) {
rimraf(tmpPath, done);
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
],
"scripts": {
"debug": "node --debug-brk ./tasks.js test",
"test": "node ./tasks.js lint test"
"test": "node ./tasks.js lint test",
"bench": "bench benchmarks"
},
"devDependencies": {
"chai": "~1.8.1",
"jshint": "~2.4.1",
"mocha": "~1.17.0",
"glob": "~3.2.8"
"glob": "~3.2.8",
"rimraf": "~2.2.6",
"bench-it": "~0.1.0"
},
"dependencies": {
"rewire": "~2.0.0"
Expand Down

0 comments on commit 61a2c84

Please sign in to comment.