diff --git a/benchmarks/insert.js b/benchmarks/insert.js index effe1d5..67c3fea 100644 --- a/benchmarks/insert.js +++ b/benchmarks/insert.js @@ -4,16 +4,31 @@ var Datastore = require('../lib/datastore') , commonUtilities = require('./commonUtilities') , execTime = require('exec-time') , profiler = new execTime('INSERT BENCH') - , n = 10000 + , n , d = new Datastore(benchDb) + , program = require('commander') ; -if (process.argv[2]) { n = parseInt(process.argv[2], 10); } +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); + d.loadDatabase(function (err) { + if (err) { return cb(err); } + if (program.withIndex) { d.ensureIndex('docNumber'); } + cb(); + }); } , function (cb) { profiler.beginProfiling(); return cb(); } , async.apply(commonUtilities.insertDocs, d, n, profiler) diff --git a/package.json b/package.json index 490aa47..f135c1c 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "mocha": "1.4.x", "request": "2.9.x", "sinon": "1.3.x", - "exec-time": "0.0.2" + "exec-time": "0.0.2", + "commander": "1.1.1" }, "scripts": { "test": "make test"