From 21b9ae75d6a5dde5b6f1ef7000c5f55fd682863c Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Fri, 10 Jan 2014 16:59:11 +0200 Subject: [PATCH] Added a benchmark suite --- benchmarks/mongodb.js | 113 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 benchmarks/mongodb.js diff --git a/benchmarks/mongodb.js b/benchmarks/mongodb.js new file mode 100644 index 0000000..b18b64a --- /dev/null +++ b/benchmarks/mongodb.js @@ -0,0 +1,113 @@ +var async = require('async'), + MongoClient = require('mongodb').MongoClient, + Iridium = require('./'); + +var objects = []; +for(var i = 0; i < 10000; i++) + objects.push({ + name: 'John', + surname: 'Doe', + birthday: new Date() + }); + +var iDB = new Iridium({ + database: 'iridium_bench' +}); + +var model = new Iridium.Model(iDB, 'iridium', { + name: String, + surname: String, + birthday: Date +}); + +iDB.register('model', model); + +function printTime(format, start) { + var ms = (new Date()).getTime() - start.getTime(); + console.log(format, ms.toString() + 'ms'); +} + +MongoClient.connect('mongodb://localhost/iridium_bench', function(err, mDB) { + if(err) throw err; + + iDB.connect(function(err) { + if(err) throw err; + + // Both databases are ready, let's start testing... + + var mDBcol = mDB.collection('mongo'); + async.series([ + function(done) { + mDBcol.remove({}, { w: 1 }, function(err, removed) { + if(err) return done(err); + return done(); + }); + }, + function(done) { + model.remove({}, function(err, removed) { + if(err) return done(err); + return done(); + }); + }, + function(done) { + console.log('MongoDB 10000 Inserts { w: 1 }'); + var start = new Date(); + mDBcol.insert(objects, { w: 1 }, function(err, inserted) { + if(err) return done(err); + printTime(' => %s', start); + return done(); + }); + }, + function(done) { + console.log('Iridium 10000 Inserts { w: 1, wrap: false }'); + var start = new Date(); + model.insert(objects, false, function(err, inserted) { + if(err) return done(err); + printTime(' => %s', start); + return done(); + }); + }, + function(done) { + console.log('MongoDB find()'); + var start = new Date(); + mDBcol.find({}).toArray(function(err, results) { + if(err) return done(err); + printTime(' => %s', start); + return done(); + }); + }, + function(done) { + console.log('Iridium find() { wrap: false }'); + var start = new Date(); + model.find({}, false, function(err, results) { + if(err) return done(err); + printTime(' => %s', start); + return done(); + }); + }, + function(done) { + console.log('MongoDB remove()'); + var start = new Date(); + mDBcol.remove({}, function(err, results) { + if(err) return done(err); + printTime(' => %s', start); + return done(); + }); + }, + function(done) { + console.log('Iridium remove()'); + var start = new Date(); + model.remove(function(err, results) { + if(err) return done(err); + printTime(' => %s', start); + return done(); + }); + } + ], function(err) { + if(err) throw err; + + mDB.close(); + iDB.disconnect(); + }); + }); +}); \ No newline at end of file