From 52af6d2330ebee3512ce2b8314b49347bfb8bdfa Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Thu, 2 May 2013 23:19:36 +0200 Subject: [PATCH] Renamed insert bench --- benchmarks/find.js | 72 ++++++++++++++++++++++++++++ benchmarks/{inserts.js => insert.js} | 8 ++-- 2 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 benchmarks/find.js rename benchmarks/{inserts.js => insert.js} (91%) diff --git a/benchmarks/find.js b/benchmarks/find.js new file mode 100644 index 0000000..caecc3a --- /dev/null +++ b/benchmarks/find.js @@ -0,0 +1,72 @@ +var Datastore = require('../lib/datastore') + , benchDb = 'workspace/find.bench.db' + , fs = require('fs') + , path = require('path') + , async = require('async') + , customUtils = require('../lib/customUtils') + , d + , order = customUtils.getRandomArray(10000) + ; + +console.log("Benchmarking find"); + +async.waterfall([ + function (cb) { + console.log("Preparing database"); + + customUtils.ensureDirectoryExists(path.dirname(benchDb), function () { + fs.exists(benchDb, function (exists) { + if (exists) { + fs.unlink(benchDb, cb); + } else { return cb(); } + }); + }); + } +, function (cb) { + d = new Datastore(benchDb); + d.loadDatabase(cb); + } +, function (cb) { + var beg = new Date() + , i = 0; + + console.log("Inserting 10,000 documents"); + + async.whilst( function () { return i < 10000; } + , function (_cb) { + i += 1; + d.insert({ docNumber: i }, function (err) { + return _cb(err); + }); + }, function (err) { + var timeTaken = (new Date()).getTime() - beg.getTime(); // In ms + if (err) { return cb(err); } + console.log("Time taken: " + (timeTaken / 1000) + "s"); + return cb(); + }); + } +, function (cb) { + var beg = new Date() + , i = 0; + + console.log("Finding 10,000 documents"); + + async.whilst( function () { return i < 10000; } + , function (_cb) { + i += 1; + d.find({ docNumber: order[i] }, function (err, docs) { + if (docs.length !== 1) { return _cb('Strangely, the doc was not found'); } + return _cb(err); + }); + }, function (err) { + var timeTaken = (new Date()).getTime() - beg.getTime(); // In ms + if (err) { return cb(err); } + console.log("Time taken: " + (timeTaken / 1000) + "s"); + return cb(); + }); + } +], function (err) { + console.log("Benchmark finished"); + + if (err) { return console.log("An error was encountered: ", err); } +}); diff --git a/benchmarks/inserts.js b/benchmarks/insert.js similarity index 91% rename from benchmarks/inserts.js rename to benchmarks/insert.js index e647ed9..2a78c22 100644 --- a/benchmarks/inserts.js +++ b/benchmarks/insert.js @@ -4,10 +4,13 @@ var Datastore = require('../lib/datastore') , path = require('path') , async = require('async') , customUtils = require('../lib/customUtils') + , n = 10000 , d ; -console.log("Benchmarking inserts"); +if (process.argv[2]) { console.log(process.argv);} + +console.log("Benchmarking insert"); async.waterfall([ function (cb) { @@ -39,10 +42,9 @@ async.waterfall([ }); }, function (err) { var timeTaken = (new Date()).getTime() - beg.getTime(); // In ms - if (err) { return cb(err); } - console.log("Time taken: " + (timeTaken / 1000) + "s"); + return cb(); }); } ], function (err) {