diff --git a/benchmarks/commonUtilities.js b/benchmarks/commonUtilities.js index b7b2c6d..72f2d07 100644 --- a/benchmarks/commonUtilities.js +++ b/benchmarks/commonUtilities.js @@ -122,3 +122,36 @@ module.exports.findOneDocs = function (d, n, profiler, cb) { 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); +}; + + + + + diff --git a/benchmarks/findOne.js b/benchmarks/findOne.js index b126593..d5248e1 100644 --- a/benchmarks/findOne.js +++ b/benchmarks/findOne.js @@ -1,11 +1,11 @@ var Datastore = require('../lib/datastore') - , benchDb = 'workspace/find.bench.db' + , benchDb = 'workspace/findOne.bench.db' , fs = require('fs') , path = require('path') , async = require('async') , commonUtilities = require('./commonUtilities') , execTime = require('exec-time') - , profiler = new execTime('FIND BENCH') + , profiler = new execTime('FINDONE BENCH') , d = new Datastore(benchDb) , n = 10000 ; diff --git a/benchmarks/update.js b/benchmarks/update.js new file mode 100644 index 0000000..acaaee6 --- /dev/null +++ b/benchmarks/update.js @@ -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); } +});