From 063c2d04cb99a4829b60dad230c5b80a4aa37033 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Thu, 2 May 2013 23:26:11 +0200 Subject: [PATCH] Able to benchmarck querying - even shittier than expected --- benchmarks/find.js | 20 ++++++++++++-------- benchmarks/insert.js | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/benchmarks/find.js b/benchmarks/find.js index caecc3a..74028a5 100644 --- a/benchmarks/find.js +++ b/benchmarks/find.js @@ -5,9 +5,13 @@ var Datastore = require('../lib/datastore') , async = require('async') , customUtils = require('../lib/customUtils') , d - , order = customUtils.getRandomArray(10000) + , n = 10000 + , order ; +if (process.argv[2]) { n = parseInt(process.argv[2], 10); } +order = customUtils.getRandomArray(n) + console.log("Benchmarking find"); async.waterfall([ @@ -30,12 +34,12 @@ async.waterfall([ var beg = new Date() , i = 0; - console.log("Inserting 10,000 documents"); + console.log("Inserting " + n + " documents"); - async.whilst( function () { return i < 10000; } + async.whilst( function () { return i < n; } , function (_cb) { - i += 1; d.insert({ docNumber: i }, function (err) { + i += 1; return _cb(err); }); }, function (err) { @@ -49,13 +53,13 @@ async.waterfall([ var beg = new Date() , i = 0; - console.log("Finding 10,000 documents"); + console.log("Finding " + n + " documents"); - async.whilst( function () { return i < 10000; } + async.whilst( function () { return i < n; } , function (_cb) { - i += 1; d.find({ docNumber: order[i] }, function (err, docs) { - if (docs.length !== 1) { return _cb('Strangely, the doc was not found'); } + i += 1; + if (docs.length !== 1) { return _cb(docs); } return _cb(err); }); }, function (err) { diff --git a/benchmarks/insert.js b/benchmarks/insert.js index 026ac8d..11abc00 100644 --- a/benchmarks/insert.js +++ b/benchmarks/insert.js @@ -36,8 +36,8 @@ async.waterfall([ async.whilst( function () { return i < n; } , function (_cb) { - i += 1; d.insert({ docNumber: i }, function (err) { + i += 1; return _cb(err); }); }, function (err) {