UNPKG

1.2 kBJavaScriptView Raw
1var Datastore = require('../lib/datastore')
2 , benchDb = 'workspace/loaddb.bench.db'
3 , fs = require('fs')
4 , path = require('path')
5 , async = require('async')
6 , commonUtilities = require('./commonUtilities')
7 , execTime = require('exec-time')
8 , profiler = new execTime('LOADDB BENCH')
9 , d = new Datastore(benchDb)
10 , program = require('commander')
11 , n
12 ;
13
14program
15 .option('-n --number [number]', 'Size of the collection to test on', parseInt)
16 .option('-i --with-index', 'Test with an index')
17 .parse(process.argv);
18
19n = program.number || 10000;
20
21console.log("----------------------------");
22console.log("Test with " + n + " documents");
23console.log(program.withIndex ? "Use an index" : "Don't use an index");
24console.log("----------------------------");
25
26async.waterfall([
27 async.apply(commonUtilities.prepareDb, benchDb)
28, function (cb) {
29 d.loadDatabase(cb);
30 }
31, function (cb) { profiler.beginProfiling(); return cb(); }
32, async.apply(commonUtilities.insertDocs, d, n, profiler)
33, async.apply(commonUtilities.loadDatabase, d, n, profiler)
34], function (err) {
35 profiler.step("Benchmark finished");
36
37 if (err) { return console.log("An error was encountered: ", err); }
38});