Benchmark removes too

pull/2/head
Louis Chatriot 12 years ago
parent 1fa23fc8d6
commit f16b7a9ab9
  1. 32
      benchmarks/commonUtilities.js
  2. 35
      benchmarks/remove.js

@ -152,6 +152,38 @@ module.exports.updateDocs = function (options, d, n, profiler, cb) {
};
/**
* Remove documents
* options is the same as the options object for update
*/
module.exports.removeDocs = function (options, d, n, profiler, cb) {
var beg = new Date()
, order = getRandomArray(n)
;
profiler.step("Removing " + n + " documents");
function runFrom(i) {
if (i === n) { // Finished
console.log("Average time for one remove in a collection of " + n + " docs: " + (profiler.elapsedSinceLastStep() / n) + "ms");
profiler.step('Finished removing ' + n + ' docs');
return cb();
}
d.remove({ docNumber: order[i] }, options, function (err, nr) {
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
// Time is about 70x smaller for an insert so the impact on the results is minimal
process.nextTick(function () {
runFrom(i + 1);
});
});
});
}
runFrom(0);
};

@ -0,0 +1,35 @@
var Datastore = require('../lib/datastore')
, benchDb = 'workspace/remove.bench.db'
, fs = require('fs')
, path = require('path')
, async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time')
, profiler = new execTime('REMOVE BENCH')
, d = new Datastore(benchDb)
, n = 10000
;
if (process.argv[2]) { n = parseInt(process.argv[2], 10); }
async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { d.loadDatabase(cb); }
, function (cb) { profiler.beginProfiling(); return cb(); }
, async.apply(commonUtilities.insertDocs, d, n, profiler)
// Test with remove only one document
, function (cb) { profiler.step('MULTI: FALSE'); return cb(); }
, async.apply(commonUtilities.removeDocs, { multi: false }, d, n, profiler)
// Test with multiple documents
//, async.apply(commonUtilities.prepareDb, benchDb)
//, function (cb) { d.loadDatabase(cb); }
//, async.apply(commonUtilities.insertDocs, d, n, profiler)
//, function (cb) { profiler.step('MULTI: TRUE'); return cb(); }
//, async.apply(commonUtilities.updateDocs, { multi: true }, d, n, profiler)
], function (err) {
profiler.step("Benchmark finished");
if (err) { return console.log("An error was encountered: ", err); }
});
Loading…
Cancel
Save