UNPKG

1.16 kBJavaScriptView Raw
1var Datastore = require('../lib/datastore')
2 , benchDb = 'workspace/insert.bench.db'
3 , async = require('async')
4 , execTime = require('exec-time')
5 , profiler = new execTime('INSERT BENCH')
6 , commonUtilities = require('./commonUtilities')
7 , config = commonUtilities.getConfiguration(benchDb)
8 , d = config.d
9 , n = config.n
10 ;
11
12async.waterfall([
13 async.apply(commonUtilities.prepareDb, benchDb)
14, function (cb) {
15 d.loadDatabase(function (err) {
16 if (err) { return cb(err); }
17 if (config.program.withIndex) {
18 d.ensureIndex({ fieldName: 'docNumber' });
19 n = 2 * n; // We will actually insert twice as many documents
20 // because the index is slower when the collection is already
21 // big. So the result given by the algorithm will be a bit worse than
22 // actual performance
23 }
24 cb();
25 });
26 }
27, function (cb) { profiler.beginProfiling(); return cb(); }
28, async.apply(commonUtilities.insertDocs, d, n, profiler)
29], function (err) {
30 profiler.step("Benchmark finished");
31
32 if (err) { return console.log("An error was encountered: ", err); }
33});