UNPKG

1.39 kBJavaScriptView Raw
1var Datastore = require('../lib/datastore')
2 , benchDb = 'workspace/remove.bench.db'
3 , fs = require('fs')
4 , path = require('path')
5 , async = require('async')
6 , execTime = require('exec-time')
7 , profiler = new execTime('REMOVE BENCH')
8 , commonUtilities = require('./commonUtilities')
9 , config = commonUtilities.getConfiguration(benchDb)
10 , d = config.d
11 , n = config.n
12 ;
13
14async.waterfall([
15 async.apply(commonUtilities.prepareDb, benchDb)
16, function (cb) {
17 d.loadDatabase(function (err) {
18 if (err) { return cb(err); }
19 if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
20 cb();
21 });
22 }
23, function (cb) { profiler.beginProfiling(); return cb(); }
24, async.apply(commonUtilities.insertDocs, d, n, profiler)
25
26// Test with remove only one document
27, function (cb) { profiler.step('MULTI: FALSE'); return cb(); }
28, async.apply(commonUtilities.removeDocs, { multi: false }, d, n, profiler)
29// Test with multiple documents
30, function (cb) { d.remove({}, { multi: true }, function () { return cb(); }); }
31, async.apply(commonUtilities.insertDocs, d, n, profiler)
32, function (cb) { profiler.step('MULTI: TRUE'); return cb(); }
33, async.apply(commonUtilities.removeDocs, { multi: true }, d, n, profiler)
34], function (err) {
35 profiler.step("Benchmark finished");
36
37 if (err) { return console.log("An error was encountered: ", err); }
38});