Permalink
Browse files

add benchmark test script

  • Loading branch information...
1 parent 49a1919 commit 43ae07b666767643778063c00e331b5b4f55a810 @aheckmann aheckmann committed Aug 31, 2011
Showing with 69 additions and 0 deletions.
  1. +69 −0 benchmarks/index.js
View
69 benchmarks/index.js
@@ -0,0 +1,69 @@
+
+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.
+
+console.error(process.memoryUsage());
+var start = new Date;
+var total = 10000;
+var i = total;
+while (i--) {
+ 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" }]
+ });
+ if (i%2)
+ a.toObject({ depopulate: true });
+ else
+ a._delta();
+}
+var time= (new Date - start)/1000;
+console.error('took %d seconds for %d docs (%d dps)', time, total, total/time);
+console.error(process.memoryUsage());
+
+console.error('last object');
+console.error(a.toObject({depopulate:true}));
+
+// --trace-opt --trace-deopt --trace-bailout

0 comments on commit 43ae07b

Please sign in to comment.