Skip to content

Commit

Permalink
Benchmark removes too
Browse files Browse the repository at this point in the history
  • Loading branch information
louischatriot committed May 3, 2013
1 parent 1fa23fc commit f16b7a9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
32 changes: 32 additions & 0 deletions benchmarks/commonUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};





35 changes: 35 additions & 0 deletions benchmarks/remove.js
Original file line number Diff line number Diff line change
@@ -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); }
});

0 comments on commit f16b7a9

Please sign in to comment.