1 | var 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 |
|
14 | program
|
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 |
|
19 | n = program.number || 10000;
|
20 |
|
21 | console.log("----------------------------");
|
22 | console.log("Test with " + n + " documents");
|
23 | console.log(program.withIndex ? "Use an index" : "Don't use an index");
|
24 | console.log("----------------------------");
|
25 |
|
26 | async.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 | });
|