diff options
Diffstat (limited to 'node_modules/mongoose/benchmarks')
| -rw-r--r-- | node_modules/mongoose/benchmarks/clone.js | 60 | ||||
| -rw-r--r-- | node_modules/mongoose/benchmarks/index.js | 128 | ||||
| -rw-r--r-- | node_modules/mongoose/benchmarks/mem.js | 149 |
3 files changed, 337 insertions, 0 deletions
diff --git a/node_modules/mongoose/benchmarks/clone.js b/node_modules/mongoose/benchmarks/clone.js new file mode 100644 index 0000000..45aa6a7 --- /dev/null +++ b/node_modules/mongoose/benchmarks/clone.js @@ -0,0 +1,60 @@ + +var mongoose = require('../') + , utils = require('../lib/utils') + , clone = utils.clone + , Schema = mongoose.Schema + +var DocSchema = new Schema({ + title: String +}); + +var AllSchema = new Schema({ + string: { type: String, required: true } + , number: { type: Number, min: 10 } + , date : Date + , bool : Boolean + , buffer: Buffer + , objectid: Schema.ObjectId + , array : Array + , strings: [String] + , numbers: [Number] + , dates : [Date] + , bools : [Boolean] + , buffers: [Buffer] + , objectids: [Schema.ObjectId] + , docs : { type: [DocSchema], validate: function () { return true }} + , s: { nest: String } +}); + +var A = mongoose.model('A', AllSchema); +var a = new A({ + string: "hello world" + , number: 444848484 + , date: new Date + , bool: true + , buffer: new Buffer(0) + , objectid: new mongoose.Types.ObjectId() + , array: [4,{},[],"asdfa"] + , strings: ["one","two","three","four"] + , numbers:[72,6493,83984643,348282.55] + , dates:[new Date, new Date, new Date] + , bools:[true, false, false, true, true] + , buffers: [new Buffer([33]), new Buffer([12])] + , objectids: [new mongoose.Types.ObjectId] + , docs: [ {title: "yo"}, {title:"nowafasdi0fas asjkdfla fa" }] + , s: { nest: 'hello there everyone!' } +}); + +var start = new Date; +var total = 100000; +var i = total; + +for (var i = 0, len = total; i < len; ++i) { + a.toObject({ depopulate: true }); +} + +var time= (new Date - start)/1000; +console.error('took %d seconds for %d docs (%d dps)', time, total, total/time); +var used = process.memoryUsage(); + +// --trace-opt --trace-deopt --trace-bailout diff --git a/node_modules/mongoose/benchmarks/index.js b/node_modules/mongoose/benchmarks/index.js new file mode 100644 index 0000000..4695113 --- /dev/null +++ b/node_modules/mongoose/benchmarks/index.js @@ -0,0 +1,128 @@ +Error.stackTraceLimit = Infinity; +var mongoose = require('../') + , Schema = mongoose.Schema; + +var DocSchema = new Schema({ + title: String +}); + +var AllSchema = new Schema({ + string: String + , number: Number + , date : Date + , bool : Boolean + , buffer: Buffer + , objectid: Schema.ObjectId + , array : Array + , strings: [String] + , numbers: [Number] + , dates : [Date] + , bools : [Boolean] + , buffers: [Buffer] + , objectids: [Schema.ObjectId] + , docs : [DocSchema] +}); + +var A = mongoose.model('A', AllSchema); + +// bench the normal way +// the try building the doc into the document prototype +// and using inheritance and bench that +// +// also, bench using listeners for each subdoc vs one +// listener that knows about all subdocs and notifies +// them. + +function run (label, fn) { + console.error('running %s', label); + var started = process.memoryUsage(); + var start = new Date; + var total = 10000; + var i = total; + while (i--) { + a = fn(); + if (i%2) + a.toObject({ depopulate: true }); + else + a._delta(); + } + var time = (new Date - start)/1000; + console.error(label + ' took %d seconds for %d docs (%d dps)', time, total, total/time); + var used = process.memoryUsage(); + console.error(((used.vsize - started.vsize) / 1048576)+' MB'); +} + +run('string', function () { + return new A({ + string: "hello world" + }); +}) +run('number', function () { + return new A({ + number: 444848484 + }); +}) +run('date', function () { + return new A({ + date: new Date + }); +}) +run('bool', function () { + return new A({ + bool: true + }); +}) +run('buffer', function () { + return new A({ + buffer: new Buffer(0) + }); +}) +run('objectid', function () { + return new A({ + objectid: new mongoose.Types.ObjectId() + }); +}) +run('array of mixed', function () { + return new A({ + array: [4,{},[],"asdfa"] + }); +}) +run('array of strings', function () { + return new A({ + strings: ["one","two","three","four"] + }); +}) +run('array of numbers', function () { + return new A({ + numbers:[72,6493,83984643,348282.55] + }); +}) +run('array of dates', function () { + return new A({ + dates:[new Date, new Date, new Date] + }); +}) +run('array of bools', function () { + return new A({ + bools:[true, false, false, true, true] + }); +}) +run('array of buffers', function () { + return new A({ + buffers: [new Buffer([33]), new Buffer([12])] + }); +}) +run('array of objectids', function () { + return new A({ + objectids: [new mongoose.Types.ObjectId] + }); +}) +run('array of docs', function () { + return new A({ + docs: [ {title: "yo"}, {title:"nowafasdi0fas asjkdfla fa" }] + }); +}) + +//console.error(a.toObject({depopulate:true})); + +// --trace-opt --trace-deopt --trace-bailout diff --git a/node_modules/mongoose/benchmarks/mem.js b/node_modules/mongoose/benchmarks/mem.js new file mode 100644 index 0000000..8ce0cfe --- /dev/null +++ b/node_modules/mongoose/benchmarks/mem.js @@ -0,0 +1,149 @@ + +var mongoose = require('../') + , Schema = mongoose.Schema; + +var db = mongoose.connect('localhost', 'testing_bench'); + +var DocSchema = new Schema({ + title: String +}); + +var AllSchema = new Schema({ + string: { type: String, required: true } + , number: { type: Number, min: 10 } + , date : Date + , bool : Boolean + , buffer: Buffer + , objectid: Schema.ObjectId + , array : Array + , strings: [String] + , numbers: [Number] + , dates : [Date] + , bools : [Boolean] + , buffers: [Buffer] + , objectids: [Schema.ObjectId] + , docs : { type: [DocSchema], validate: function () { return true }} + , s: { nest: String } +}); + +var A = mongoose.model('A', AllSchema); + +var methods = []; +methods.push(function (a, cb) { + A.findOne({ _id: a._id }, cb); +}); // 2 MB +methods.push(function (a, cb) { + A.find({ _id: a._id, bool: a.bool }, cb); +}); // 3.8 MB +methods.push(function (a, cb) { + A.findById(a._id, cb); +}); // 4.6 MB +methods.push(function (a, cb) { + A.where('number', a.number).sort('_id', -1).limit(10).run(cb) +}); // 4.8 MB +methods.push(function (a, cb) { + A.where('date', a.date).select('string').limit(10).run(cb) +}); // 3.5 mb +methods.push(function (a, cb) { + A.where('date', a.date).select('string', 'bool').asc('date').limit(10).run(cb) +}); // 3.5 MB +methods.push(function (a, cb) { + A.find('date', a.date).where('array').$in(3).limit(10).run(cb) +}); // 1.82 MB +methods.push(function (a, cb) { + A.update({ _id: a._id }, { $addToset: { array: "heeeeello" }}, cb); +}); // 3.32 MB +methods.push(function (a, cb) { + A.remove({ _id: a._id }, cb); +}); // 3.32 MB +methods.push(function (a, cb) { + A.find().where('objectids').exists().only('dates').limit(10).exec(cb); +}); // 3.32 MB +methods.push(function (a, cb) { + A.count({ strings: a.strings[2], number: a.number }, cb); +}); // 3.32 MB +methods.push(function (a, cb) { + a.string= "asdfaf"; + a.number = 38383838; + a.date= new Date; + a.bool = false; + a.array.push(3); + a.dates.push(new Date); + a.bools.$pushAll([true, false]); + a.docs.$addToSet({ title: 'woot' }); + a.strings.remove("three"); + a.numbers.$pull(72); + a.objectids.$pop(); + a.docs.$pullAll(a.docs); + a.s.nest = "aooooooga"; + + if (i%2) + a.toObject({ depopulate: true }); + else + a._delta(); + + cb(); +}); + +var started = process.memoryUsage(); +var start = new Date; +var total = 500; +var i = total; + +mongoose.connection.on('open', function () { + mongoose.connection.db.dropDatabase(function () { + + ;(function cycle () { + if (0 === i--) return done(); + + var a = new A({ + string: "hello world" + , number: 444848484 + , date: new Date + , bool: true + , buffer: new Buffer(0) + , objectid: new mongoose.Types.ObjectId() + , array: [4,{},[],"asdfa"] + , strings: ["one","two","three","four"] + , numbers:[72,6493,83984643,348282.55] + , dates:[new Date, new Date, new Date] + , bools:[true, false, false, true, true] + , buffers: [new Buffer([33]), new Buffer([12])] + , objectids: [new mongoose.Types.ObjectId] + , docs: [ {title: "yo"}, {title:"nowafasdi0fas asjkdfla fa" }] + }); + + a.save(function (err) { + methods[Math.random()*methods.length|0](a, function () { + process.nextTick(cycle); + }) + }); + + //if (i%2) + //a.toObject({ depopulate: true }); + //else + //a._delta(); + + if (!(i%50)) { + var u = process.memoryUsage(); + console.error('rss: %d, vsize: %d, heapTotal: %d, heapUsed: %d', + u.rss, u.vsize, u.heapTotal, u.heapUsed); + } + })() + + function done () { + var time= (new Date - start)/1000; + console.error('took %d seconds for %d docs (%d dps)', time, total, total/time); + var used = process.memoryUsage(); + console.error(((used.vsize - started.vsize) / 1048576)+' MB'); + + //console.error(a.toObject({depopulate:true})); + + mongoose.connection.db.dropDatabase(function () { + mongoose.connection.close(); + }); + } + + // --trace-opt --trace-deopt --trace-bailout + }) +}) |
