Benchmarks work with all versions of node now

pull/2/head
Louis Chatriot 12 years ago
parent 3ce11b7bea
commit ce0888006a
  1. 19
      benchmarks/commonUtilities.js

@ -5,8 +5,15 @@
var customUtils = require('../lib/customUtils') var customUtils = require('../lib/customUtils')
, fs = require('fs') , fs = require('fs')
, path = require('path') , path = require('path')
, executeAsap // process.nextTick or setImmediate depending on your Node version
; ;
try {
executeAsap = setImmediate;
} catch (e) {
executeAsap = process.nextTick;
}
/** /**
* Ensure the workspace exists and the db is empty * Ensure the workspace exists and the db is empty
@ -58,7 +65,7 @@ module.exports.insertDocs = function (d, n, profiler, cb) {
} }
d.insert({ docNumber: i }, function (err) { d.insert({ docNumber: i }, function (err) {
process.nextTick(function () { executeAsap(function () {
runFrom(i + 1); runFrom(i + 1);
}); });
}); });
@ -86,7 +93,7 @@ module.exports.findDocs = function (d, n, profiler, cb) {
d.find({ docNumber: order[i] }, function (err, docs) { d.find({ docNumber: order[i] }, function (err, docs) {
if (docs.length !== 1 || docs[0].docNumber !== order[i]) { return cb('One find didnt work'); } if (docs.length !== 1 || docs[0].docNumber !== order[i]) { return cb('One find didnt work'); }
process.nextTick(function () { executeAsap(function () {
runFrom(i + 1); runFrom(i + 1);
}); });
}); });
@ -114,7 +121,7 @@ module.exports.findOneDocs = function (d, n, profiler, cb) {
d.findOne({ docNumber: order[i] }, function (err, doc) { d.findOne({ docNumber: order[i] }, function (err, doc) {
if (!doc || doc.docNumber !== order[i]) { return cb('One find didnt work'); } if (!doc || doc.docNumber !== order[i]) { return cb('One find didnt work'); }
process.nextTick(function () { executeAsap(function () {
runFrom(i + 1); runFrom(i + 1);
}); });
}); });
@ -143,7 +150,7 @@ module.exports.updateDocs = function (options, d, n, profiler, cb) {
d.update({ docNumber: order[i] }, { newDocNumber: i }, options, function (err, nr) { d.update({ docNumber: order[i] }, { newDocNumber: i }, options, function (err, nr) {
if (nr !== 1) { return cb('One update didnt work'); } if (nr !== 1) { return cb('One update didnt work'); }
process.nextTick(function () { executeAsap(function () {
runFrom(i + 1); runFrom(i + 1);
}); });
}); });
@ -174,7 +181,7 @@ module.exports.removeDocs = function (options, d, n, profiler, cb) {
if (nr !== 1) { return cb('One remove didnt work'); } if (nr !== 1) { return cb('One remove didnt work'); }
d.insert({ docNumber: order[i] }, function (err) { // Reinserting just removed document so that the collection size doesn't change d.insert({ docNumber: order[i] }, function (err) { // Reinserting just removed document so that the collection size doesn't change
// Time is about 70x smaller for an insert so the impact on the results is minimal // Time is about 70x smaller for an insert so the impact on the results is minimal
process.nextTick(function () { executeAsap(function () {
runFrom(i + 1); runFrom(i + 1);
}); });
}); });
@ -202,7 +209,7 @@ module.exports.loadDatabase = function (d, n, profiler, cb) {
} }
d.loadDatabase(function (err) { d.loadDatabase(function (err) {
process.nextTick(function () { executeAsap(function () {
runFrom(i + 1); runFrom(i + 1);
}); });
}); });

Loading…
Cancel
Save