stuff
This commit is contained in:
308
buildfiles/app/node_modules/nedb/benchmarks/commonUtilities.js
generated
vendored
Executable file
308
buildfiles/app/node_modules/nedb/benchmarks/commonUtilities.js
generated
vendored
Executable file
@ -0,0 +1,308 @@
|
||||
/**
|
||||
* Functions that are used in several benchmark tests
|
||||
*/
|
||||
|
||||
var customUtils = require('../lib/customUtils')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, Datastore = require('../lib/datastore')
|
||||
, Persistence = require('../lib/persistence')
|
||||
, executeAsap // process.nextTick or setImmediate depending on your Node version
|
||||
;
|
||||
|
||||
try {
|
||||
executeAsap = setImmediate;
|
||||
} catch (e) {
|
||||
executeAsap = process.nextTick;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configure the benchmark
|
||||
*/
|
||||
module.exports.getConfiguration = function (benchDb) {
|
||||
var d, n
|
||||
, program = require('commander')
|
||||
;
|
||||
|
||||
program
|
||||
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
|
||||
.option('-i --with-index', 'Use an index')
|
||||
.option('-m --in-memory', 'Test with an in-memory only store')
|
||||
.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(program.inMemory ? "Use an in-memory datastore" : "Use a persistent datastore");
|
||||
console.log("----------------------------");
|
||||
|
||||
d = new Datastore({ filename: benchDb
|
||||
, inMemoryOnly: program.inMemory
|
||||
});
|
||||
|
||||
return { n: n, d: d, program: program };
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Ensure the workspace exists and the db datafile is empty
|
||||
*/
|
||||
module.exports.prepareDb = function (filename, cb) {
|
||||
Persistence.ensureDirectoryExists(path.dirname(filename), function () {
|
||||
fs.exists(filename, function (exists) {
|
||||
if (exists) {
|
||||
fs.unlink(filename, cb);
|
||||
} else { return cb(); }
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return an array with the numbers from 0 to n-1, in a random order
|
||||
* Uses Fisher Yates algorithm
|
||||
* Useful to get fair tests
|
||||
*/
|
||||
function getRandomArray (n) {
|
||||
var res = []
|
||||
, i, j, temp
|
||||
;
|
||||
|
||||
for (i = 0; i < n; i += 1) { res[i] = i; }
|
||||
|
||||
for (i = n - 1; i >= 1; i -= 1) {
|
||||
j = Math.floor((i + 1) * Math.random());
|
||||
temp = res[i];
|
||||
res[i] = res[j];
|
||||
res[j] = temp;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
module.exports.getRandomArray = getRandomArray;
|
||||
|
||||
|
||||
/**
|
||||
* Insert a certain number of documents for testing
|
||||
*/
|
||||
module.exports.insertDocs = function (d, n, profiler, cb) {
|
||||
var beg = new Date()
|
||||
, order = getRandomArray(n)
|
||||
;
|
||||
|
||||
profiler.step('Begin inserting ' + n + ' docs');
|
||||
|
||||
function runFrom(i) {
|
||||
if (i === n) { // Finished
|
||||
var opsPerSecond = Math.floor(1000* n / profiler.elapsedSinceLastStep());
|
||||
console.log("===== RESULT (insert) ===== " + opsPerSecond + " ops/s");
|
||||
profiler.step('Finished inserting ' + n + ' docs');
|
||||
profiler.insertOpsPerSecond = opsPerSecond;
|
||||
return cb();
|
||||
}
|
||||
|
||||
d.insert({ docNumber: order[i] }, function (err) {
|
||||
executeAsap(function () {
|
||||
runFrom(i + 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
runFrom(0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Find documents with find
|
||||
*/
|
||||
module.exports.findDocs = function (d, n, profiler, cb) {
|
||||
var beg = new Date()
|
||||
, order = getRandomArray(n)
|
||||
;
|
||||
|
||||
profiler.step("Finding " + n + " documents");
|
||||
|
||||
function runFrom(i) {
|
||||
if (i === n) { // Finished
|
||||
console.log("===== RESULT (find) ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s");
|
||||
profiler.step('Finished finding ' + n + ' docs');
|
||||
return cb();
|
||||
}
|
||||
|
||||
d.find({ docNumber: order[i] }, function (err, docs) {
|
||||
if (docs.length !== 1 || docs[0].docNumber !== order[i]) { return cb('One find didnt work'); }
|
||||
executeAsap(function () {
|
||||
runFrom(i + 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
runFrom(0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Find documents with find and the $in operator
|
||||
*/
|
||||
module.exports.findDocsWithIn = function (d, n, profiler, cb) {
|
||||
var beg = new Date()
|
||||
, order = getRandomArray(n)
|
||||
, ins = [], i, j
|
||||
, arraySize = Math.min(10, n) // The array for $in needs to be smaller than n (inclusive)
|
||||
;
|
||||
|
||||
// Preparing all the $in arrays, will take some time
|
||||
for (i = 0; i < n; i += 1) {
|
||||
ins[i] = [];
|
||||
|
||||
for (j = 0; j < arraySize; j += 1) {
|
||||
ins[i].push((i + j) % n);
|
||||
}
|
||||
}
|
||||
|
||||
profiler.step("Finding " + n + " documents WITH $IN OPERATOR");
|
||||
|
||||
function runFrom(i) {
|
||||
if (i === n) { // Finished
|
||||
console.log("===== RESULT (find with in selector) ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s");
|
||||
profiler.step('Finished finding ' + n + ' docs');
|
||||
return cb();
|
||||
}
|
||||
|
||||
d.find({ docNumber: { $in: ins[i] } }, function (err, docs) {
|
||||
if (docs.length !== arraySize) { return cb('One find didnt work'); }
|
||||
executeAsap(function () {
|
||||
runFrom(i + 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
runFrom(0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Find documents with findOne
|
||||
*/
|
||||
module.exports.findOneDocs = function (d, n, profiler, cb) {
|
||||
var beg = new Date()
|
||||
, order = getRandomArray(n)
|
||||
;
|
||||
|
||||
profiler.step("FindingOne " + n + " documents");
|
||||
|
||||
function runFrom(i) {
|
||||
if (i === n) { // Finished
|
||||
console.log("===== RESULT (findOne) ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s");
|
||||
profiler.step('Finished finding ' + n + ' docs');
|
||||
return cb();
|
||||
}
|
||||
|
||||
d.findOne({ docNumber: order[i] }, function (err, doc) {
|
||||
if (!doc || doc.docNumber !== order[i]) { return cb('One find didnt work'); }
|
||||
executeAsap(function () {
|
||||
runFrom(i + 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
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("===== RESULT (update) ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s");
|
||||
profiler.step('Finished updating ' + n + ' docs');
|
||||
return cb();
|
||||
}
|
||||
|
||||
// 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 (err) { return cb(err); }
|
||||
if (nr !== 1) { return cb('One update didnt work'); }
|
||||
executeAsap(function () {
|
||||
runFrom(i + 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
runFrom(0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
// opsPerSecond corresponds to 1 insert + 1 remove, needed to keep collection size at 10,000
|
||||
// We need to subtract the time taken by one insert to get the time actually taken by one remove
|
||||
var opsPerSecond = Math.floor(1000 * n / profiler.elapsedSinceLastStep());
|
||||
var removeOpsPerSecond = Math.floor(1 / ((1 / opsPerSecond) - (1 / profiler.insertOpsPerSecond)))
|
||||
console.log("===== RESULT (remove) ===== " + removeOpsPerSecond + " ops/s");
|
||||
profiler.step('Finished removing ' + n + ' docs');
|
||||
return cb();
|
||||
}
|
||||
|
||||
d.remove({ docNumber: order[i] }, options, function (err, nr) {
|
||||
if (err) { return cb(err); }
|
||||
if (nr !== 1) { return cb('One remove didnt work'); }
|
||||
d.insert({ docNumber: order[i] }, function (err) { // We need to reinsert the doc so that we keep the collection's size at n
|
||||
// So actually we're calculating the average time taken by one insert + one remove
|
||||
executeAsap(function () {
|
||||
runFrom(i + 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
runFrom(0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Load database
|
||||
*/
|
||||
module.exports.loadDatabase = function (d, n, profiler, cb) {
|
||||
var beg = new Date()
|
||||
, order = getRandomArray(n)
|
||||
;
|
||||
|
||||
profiler.step("Loading the database " + n + " times");
|
||||
|
||||
function runFrom(i) {
|
||||
if (i === n) { // Finished
|
||||
console.log("===== RESULT ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s");
|
||||
profiler.step('Finished loading a database' + n + ' times');
|
||||
return cb();
|
||||
}
|
||||
|
||||
d.loadDatabase(function (err) {
|
||||
executeAsap(function () {
|
||||
runFrom(i + 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
runFrom(0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
51
buildfiles/app/node_modules/nedb/benchmarks/ensureIndex.js
generated
vendored
Executable file
51
buildfiles/app/node_modules/nedb/benchmarks/ensureIndex.js
generated
vendored
Executable file
@ -0,0 +1,51 @@
|
||||
var Datastore = require('../lib/datastore')
|
||||
, benchDb = 'workspace/insert.bench.db'
|
||||
, async = require('async')
|
||||
, commonUtilities = require('./commonUtilities')
|
||||
, execTime = require('exec-time')
|
||||
, profiler = new execTime('INSERT BENCH')
|
||||
, d = new Datastore(benchDb)
|
||||
, program = require('commander')
|
||||
, n
|
||||
;
|
||||
|
||||
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("----------------------------");
|
||||
|
||||
async.waterfall([
|
||||
async.apply(commonUtilities.prepareDb, benchDb)
|
||||
, function (cb) {
|
||||
d.loadDatabase(function (err) {
|
||||
if (err) { return cb(err); }
|
||||
cb();
|
||||
});
|
||||
}
|
||||
, function (cb) { profiler.beginProfiling(); return cb(); }
|
||||
, async.apply(commonUtilities.insertDocs, d, n, profiler)
|
||||
, function (cb) {
|
||||
var i;
|
||||
|
||||
profiler.step('Begin calling ensureIndex ' + n + ' times');
|
||||
|
||||
for (i = 0; i < n; i += 1) {
|
||||
d.ensureIndex({ fieldName: 'docNumber' });
|
||||
delete d.indexes.docNumber;
|
||||
}
|
||||
|
||||
console.log("Average time for one ensureIndex: " + (profiler.elapsedSinceLastStep() / n) + "ms");
|
||||
profiler.step('Finished calling ensureIndex ' + n + ' times');
|
||||
}
|
||||
], function (err) {
|
||||
profiler.step("Benchmark finished");
|
||||
|
||||
if (err) { return console.log("An error was encountered: ", err); }
|
||||
});
|
||||
|
30
buildfiles/app/node_modules/nedb/benchmarks/find.js
generated
vendored
Executable file
30
buildfiles/app/node_modules/nedb/benchmarks/find.js
generated
vendored
Executable file
@ -0,0 +1,30 @@
|
||||
var Datastore = require('../lib/datastore')
|
||||
, benchDb = 'workspace/find.bench.db'
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, async = require('async')
|
||||
, execTime = require('exec-time')
|
||||
, profiler = new execTime('FIND BENCH')
|
||||
, commonUtilities = require('./commonUtilities')
|
||||
, config = commonUtilities.getConfiguration(benchDb)
|
||||
, d = config.d
|
||||
, n = config.n
|
||||
;
|
||||
|
||||
async.waterfall([
|
||||
async.apply(commonUtilities.prepareDb, benchDb)
|
||||
, function (cb) {
|
||||
d.loadDatabase(function (err) {
|
||||
if (err) { return cb(err); }
|
||||
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
|
||||
cb();
|
||||
});
|
||||
}
|
||||
, function (cb) { profiler.beginProfiling(); return cb(); }
|
||||
, async.apply(commonUtilities.insertDocs, d, n, profiler)
|
||||
, async.apply(commonUtilities.findDocs, d, n, profiler)
|
||||
], function (err) {
|
||||
profiler.step("Benchmark finished");
|
||||
|
||||
if (err) { return console.log("An error was encountered: ", err); }
|
||||
});
|
31
buildfiles/app/node_modules/nedb/benchmarks/findOne.js
generated
vendored
Executable file
31
buildfiles/app/node_modules/nedb/benchmarks/findOne.js
generated
vendored
Executable file
@ -0,0 +1,31 @@
|
||||
var Datastore = require('../lib/datastore')
|
||||
, benchDb = 'workspace/findOne.bench.db'
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, async = require('async')
|
||||
, execTime = require('exec-time')
|
||||
, profiler = new execTime('FINDONE BENCH')
|
||||
, commonUtilities = require('./commonUtilities')
|
||||
, config = commonUtilities.getConfiguration(benchDb)
|
||||
, d = config.d
|
||||
, n = config.n
|
||||
;
|
||||
|
||||
async.waterfall([
|
||||
async.apply(commonUtilities.prepareDb, benchDb)
|
||||
, function (cb) {
|
||||
d.loadDatabase(function (err) {
|
||||
if (err) { return cb(err); }
|
||||
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
|
||||
cb();
|
||||
});
|
||||
}
|
||||
, function (cb) { profiler.beginProfiling(); return cb(); }
|
||||
, async.apply(commonUtilities.insertDocs, d, n, profiler)
|
||||
, function (cb) { setTimeout(function () {cb();}, 500); }
|
||||
, async.apply(commonUtilities.findOneDocs, d, n, profiler)
|
||||
], function (err) {
|
||||
profiler.step("Benchmark finished");
|
||||
|
||||
if (err) { return console.log("An error was encountered: ", err); }
|
||||
});
|
30
buildfiles/app/node_modules/nedb/benchmarks/findWithIn.js
generated
vendored
Executable file
30
buildfiles/app/node_modules/nedb/benchmarks/findWithIn.js
generated
vendored
Executable file
@ -0,0 +1,30 @@
|
||||
var Datastore = require('../lib/datastore')
|
||||
, benchDb = 'workspace/find.bench.db'
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, async = require('async')
|
||||
, execTime = require('exec-time')
|
||||
, profiler = new execTime('FIND BENCH')
|
||||
, commonUtilities = require('./commonUtilities')
|
||||
, config = commonUtilities.getConfiguration(benchDb)
|
||||
, d = config.d
|
||||
, n = config.n
|
||||
;
|
||||
|
||||
async.waterfall([
|
||||
async.apply(commonUtilities.prepareDb, benchDb)
|
||||
, function (cb) {
|
||||
d.loadDatabase(function (err) {
|
||||
if (err) { return cb(err); }
|
||||
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
|
||||
cb();
|
||||
});
|
||||
}
|
||||
, function (cb) { profiler.beginProfiling(); return cb(); }
|
||||
, async.apply(commonUtilities.insertDocs, d, n, profiler)
|
||||
, async.apply(commonUtilities.findDocsWithIn, d, n, profiler)
|
||||
], function (err) {
|
||||
profiler.step("Benchmark finished");
|
||||
|
||||
if (err) { return console.log("An error was encountered: ", err); }
|
||||
});
|
33
buildfiles/app/node_modules/nedb/benchmarks/insert.js
generated
vendored
Executable file
33
buildfiles/app/node_modules/nedb/benchmarks/insert.js
generated
vendored
Executable file
@ -0,0 +1,33 @@
|
||||
var Datastore = require('../lib/datastore')
|
||||
, benchDb = 'workspace/insert.bench.db'
|
||||
, async = require('async')
|
||||
, execTime = require('exec-time')
|
||||
, profiler = new execTime('INSERT BENCH')
|
||||
, commonUtilities = require('./commonUtilities')
|
||||
, config = commonUtilities.getConfiguration(benchDb)
|
||||
, d = config.d
|
||||
, n = config.n
|
||||
;
|
||||
|
||||
async.waterfall([
|
||||
async.apply(commonUtilities.prepareDb, benchDb)
|
||||
, function (cb) {
|
||||
d.loadDatabase(function (err) {
|
||||
if (err) { return cb(err); }
|
||||
if (config.program.withIndex) {
|
||||
d.ensureIndex({ fieldName: 'docNumber' });
|
||||
n = 2 * n; // We will actually insert twice as many documents
|
||||
// because the index is slower when the collection is already
|
||||
// big. So the result given by the algorithm will be a bit worse than
|
||||
// actual performance
|
||||
}
|
||||
cb();
|
||||
});
|
||||
}
|
||||
, function (cb) { profiler.beginProfiling(); return cb(); }
|
||||
, async.apply(commonUtilities.insertDocs, d, n, profiler)
|
||||
], function (err) {
|
||||
profiler.step("Benchmark finished");
|
||||
|
||||
if (err) { return console.log("An error was encountered: ", err); }
|
||||
});
|
38
buildfiles/app/node_modules/nedb/benchmarks/loadDatabase.js
generated
vendored
Executable file
38
buildfiles/app/node_modules/nedb/benchmarks/loadDatabase.js
generated
vendored
Executable file
@ -0,0 +1,38 @@
|
||||
var Datastore = require('../lib/datastore')
|
||||
, benchDb = 'workspace/loaddb.bench.db'
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, async = require('async')
|
||||
, commonUtilities = require('./commonUtilities')
|
||||
, execTime = require('exec-time')
|
||||
, profiler = new execTime('LOADDB BENCH')
|
||||
, d = new Datastore(benchDb)
|
||||
, program = require('commander')
|
||||
, n
|
||||
;
|
||||
|
||||
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.apply(commonUtilities.prepareDb, benchDb)
|
||||
, function (cb) {
|
||||
d.loadDatabase(cb);
|
||||
}
|
||||
, function (cb) { profiler.beginProfiling(); return cb(); }
|
||||
, async.apply(commonUtilities.insertDocs, d, n, profiler)
|
||||
, async.apply(commonUtilities.loadDatabase, d, n, profiler)
|
||||
], function (err) {
|
||||
profiler.step("Benchmark finished");
|
||||
|
||||
if (err) { return console.log("An error was encountered: ", err); }
|
||||
});
|
38
buildfiles/app/node_modules/nedb/benchmarks/remove.js
generated
vendored
Executable file
38
buildfiles/app/node_modules/nedb/benchmarks/remove.js
generated
vendored
Executable file
@ -0,0 +1,38 @@
|
||||
var Datastore = require('../lib/datastore')
|
||||
, benchDb = 'workspace/remove.bench.db'
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, async = require('async')
|
||||
, execTime = require('exec-time')
|
||||
, profiler = new execTime('REMOVE BENCH')
|
||||
, commonUtilities = require('./commonUtilities')
|
||||
, config = commonUtilities.getConfiguration(benchDb)
|
||||
, d = config.d
|
||||
, n = config.n
|
||||
;
|
||||
|
||||
async.waterfall([
|
||||
async.apply(commonUtilities.prepareDb, benchDb)
|
||||
, function (cb) {
|
||||
d.loadDatabase(function (err) {
|
||||
if (err) { return cb(err); }
|
||||
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
|
||||
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
|
||||
, function (cb) { d.remove({}, { multi: true }, function () { return cb(); }); }
|
||||
, async.apply(commonUtilities.insertDocs, d, n, profiler)
|
||||
, function (cb) { profiler.step('MULTI: TRUE'); return cb(); }
|
||||
, async.apply(commonUtilities.removeDocs, { multi: true }, d, n, profiler)
|
||||
], function (err) {
|
||||
profiler.step("Benchmark finished");
|
||||
|
||||
if (err) { return console.log("An error was encountered: ", err); }
|
||||
});
|
39
buildfiles/app/node_modules/nedb/benchmarks/update.js
generated
vendored
Executable file
39
buildfiles/app/node_modules/nedb/benchmarks/update.js
generated
vendored
Executable file
@ -0,0 +1,39 @@
|
||||
var Datastore = require('../lib/datastore')
|
||||
, benchDb = 'workspace/update.bench.db'
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, async = require('async')
|
||||
, execTime = require('exec-time')
|
||||
, profiler = new execTime('UPDATE BENCH')
|
||||
, commonUtilities = require('./commonUtilities')
|
||||
, config = commonUtilities.getConfiguration(benchDb)
|
||||
, d = config.d
|
||||
, n = config.n
|
||||
;
|
||||
|
||||
async.waterfall([
|
||||
async.apply(commonUtilities.prepareDb, benchDb)
|
||||
, function (cb) {
|
||||
d.loadDatabase(function (err) {
|
||||
if (err) { return cb(err); }
|
||||
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
|
||||
cb();
|
||||
});
|
||||
}
|
||||
, function (cb) { profiler.beginProfiling(); return cb(); }
|
||||
, async.apply(commonUtilities.insertDocs, d, n, profiler)
|
||||
|
||||
// Test with update only one document
|
||||
, function (cb) { profiler.step('MULTI: FALSE'); return cb(); }
|
||||
, async.apply(commonUtilities.updateDocs, { multi: false }, d, n, profiler)
|
||||
|
||||
// Test with multiple documents
|
||||
, function (cb) { d.remove({}, { multi: true }, function (err) { return 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); }
|
||||
});
|
Reference in New Issue
Block a user