Benchmarking updates

pull/2/head
Louis Chatriot 12 years ago
parent b74cffc25a
commit b450cae878
  1. 33
      benchmarks/commonUtilities.js
  2. 4
      benchmarks/findOne.js
  3. 28
      benchmarks/update.js

@ -122,3 +122,36 @@ module.exports.findOneDocs = function (d, n, profiler, cb) {
runFrom(0); runFrom(0);
}; };
/**
* Update documents
* options is the same as the options object for update
*/
module.exports.updateDocs = function (options, d, n, profiler, cb) {
var beg = new Date()
, order = getRandomArray(n)
;
profiler.step("Updating " + n + " documents");
function runFrom(i) {
if (i === n) { // Finished
console.log("Average time for one update in a collection of " + n + " docs: " + (profiler.elapsedSinceLastStep() / n) + "ms");
profiler.step('Finished updating ' + n + ' docs');
return cb();
}
d.update({ docNumber: order[i] }, { newDocNumber: i }, options, function (err, nr) {
if (nr !== 1) { return cb('One update didnt work'); }
process.nextTick(function () {
runFrom(i + 1);
});
});
}
runFrom(0);
};

@ -1,11 +1,11 @@
var Datastore = require('../lib/datastore') var Datastore = require('../lib/datastore')
, benchDb = 'workspace/find.bench.db' , benchDb = 'workspace/findOne.bench.db'
, fs = require('fs') , fs = require('fs')
, path = require('path') , path = require('path')
, async = require('async') , async = require('async')
, commonUtilities = require('./commonUtilities') , commonUtilities = require('./commonUtilities')
, execTime = require('exec-time') , execTime = require('exec-time')
, profiler = new execTime('FIND BENCH') , profiler = new execTime('FINDONE BENCH')
, d = new Datastore(benchDb) , d = new Datastore(benchDb)
, n = 10000 , n = 10000
; ;

@ -0,0 +1,28 @@
var Datastore = require('../lib/datastore')
, benchDb = 'workspace/update.bench.db'
, fs = require('fs')
, path = require('path')
, async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time')
, profiler = new execTime('UPDATE 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)
, function (cb) { profiler.step('MULTI: FALSE'); return cb(); }
, async.apply(commonUtilities.updateDocs, { multi: false }, d, n, profiler)
], function (err) {
profiler.step("Benchmark finished");
if (err) { return console.log("An error was encountered: ", err); }
});
Loading…
Cancel
Save