Benchmark for update done

pull/2/head
Louis Chatriot 12 years ago
parent 77b95ce7dc
commit 4d7a3823bd
  1. 3
      benchmarks/commonUtilities.js
  2. 1
      benchmarks/insert.js
  3. 25
      benchmarks/remove.js
  4. 25
      benchmarks/update.js
  5. 12
      lib/datastore.js

@ -154,7 +154,8 @@ module.exports.updateDocs = function (options, d, n, profiler, cb) {
return cb(); return cb();
} }
d.update({ docNumber: order[i] }, { newDocNumber: i }, options, function (err, nr) { // Will not actually modify the document but will take the same time
d.update({ docNumber: order[i] }, { docNumber: order[i] }, options, function (err, nr) {
if (nr !== 1) { return cb('One update didnt work'); } if (nr !== 1) { return cb('One update didnt work'); }
executeAsap(function () { executeAsap(function () {
runFrom(i + 1); runFrom(i + 1);

@ -21,7 +21,6 @@ console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index"); console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log("----------------------------"); console.log("----------------------------");
async.waterfall([ async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb) async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { , function (cb) {

@ -7,14 +7,33 @@ var Datastore = require('../lib/datastore')
, execTime = require('exec-time') , execTime = require('exec-time')
, profiler = new execTime('REMOVE BENCH') , profiler = new execTime('REMOVE BENCH')
, d = new Datastore(benchDb) , d = new Datastore(benchDb)
, n = 10000 , program = require('commander')
, n
; ;
if (process.argv[2]) { n = parseInt(process.argv[2], 10); } program
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
.option('-i --with-index', 'Test with an index')
.parse(process.argv);
n = program.number || 10000;
console.log("----------------------------");
console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log("----------------------------");
async.waterfall([ async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb) async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { d.loadDatabase(cb); } , function (cb) {
d.loadDatabase(function (err) {
if (err) { return cb(err); }
if (program.withIndex) {
d.ensureIndex({ fieldName: 'docNumber' });
}
cb();
});
}
, function (cb) { profiler.beginProfiling(); return cb(); } , function (cb) { profiler.beginProfiling(); return cb(); }
, async.apply(commonUtilities.insertDocs, d, n, profiler) , async.apply(commonUtilities.insertDocs, d, n, profiler)

@ -7,14 +7,33 @@ var Datastore = require('../lib/datastore')
, execTime = require('exec-time') , execTime = require('exec-time')
, profiler = new execTime('UPDATE BENCH') , profiler = new execTime('UPDATE BENCH')
, d = new Datastore(benchDb) , d = new Datastore(benchDb)
, n = 10000 , program = require('commander')
, n
; ;
if (process.argv[2]) { n = parseInt(process.argv[2], 10); } program
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
.option('-i --with-index', 'Test with an index')
.parse(process.argv);
n = program.number || 10000;
console.log("----------------------------");
console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log("----------------------------");
async.waterfall([ async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb) async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { d.loadDatabase(cb); } , function (cb) {
d.loadDatabase(function (err) {
if (err) { return cb(err); }
if (program.withIndex) {
d.ensureIndex({ fieldName: 'docNumber' });
}
cb();
});
}
, function (cb) { profiler.beginProfiling(); return cb(); } , function (cb) { profiler.beginProfiling(); return cb(); }
, async.apply(commonUtilities.insertDocs, d, n, profiler) , async.apply(commonUtilities.insertDocs, d, n, profiler)

@ -340,6 +340,7 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
, numReplaced = 0 , numReplaced = 0
, multi, upsert , multi, upsert
, updatedDocs = [] , updatedDocs = []
, candidates
, i , i
; ;
@ -367,12 +368,14 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
}); });
} }
, function () { // Perform the update , function () { // Perform the update
candidates = self.getCandidates(query)
try { try {
for (i = 0; i < self.data.length; i += 1) { for (i = 0; i < candidates.length; i += 1) {
if (model.match(self.data[i], query) && (multi || numReplaced === 0)) { if (model.match(candidates[i], query) && (multi || numReplaced === 0)) {
numReplaced += 1; numReplaced += 1;
self.data[i] = model.modify(self.data[i], updateQuery); candidates[i] = model.modify(candidates[i], updateQuery);
updatedDocs.push(self.data[i]); updatedDocs.push(candidates[i]);
} }
} }
} catch (err) { } catch (err) {
@ -404,6 +407,7 @@ Datastore.prototype.update = function () {
Datastore.prototype._remove = function (query, options, cb) { Datastore.prototype._remove = function (query, options, cb) {
var callback var callback
, self = this , self = this
, candidates = this.getCandidates(query)
, numRemoved = 0 , numRemoved = 0
, multi , multi
, newData = [] , newData = []

Loading…
Cancel
Save