-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple event emitter benchmark
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var debug = require('util').debug, | ||
inspect = require('util').inspect, | ||
inherits = require('util').inherits, | ||
net = require('net'), | ||
EventEmitter = require("events").EventEmitter; | ||
|
||
var COUNT = 1000000; | ||
|
||
var Emitter = function() { | ||
} | ||
|
||
inherits(Emitter, EventEmitter); | ||
|
||
Emitter.prototype.start = function() { | ||
for(var i = 0; i < COUNT; i++) { | ||
this.emit("data", "============================================== data") | ||
} | ||
} | ||
|
||
Emitter.prototype.start2 = function(callback) { | ||
for(var i = 0; i < COUNT; i++) { | ||
callback(null, "============================================== data") | ||
} | ||
} | ||
|
||
// Create test object | ||
var emitObj = new Emitter(); | ||
emitObj.on("data", function(data) { | ||
}) | ||
|
||
console.log(COUNT + "x (objectBSON = BSON.serialize(object))") | ||
start = new Date | ||
|
||
emitObj.start(); | ||
|
||
end = new Date | ||
console.log("time = ", end - start, "ms -", COUNT * 1000 / (end - start), " ops/sec") | ||
|
||
|
||
console.log(COUNT + "x (objectBSON = BSON.serialize(object))") | ||
start = new Date | ||
|
||
emitObj.start2(function(err, data) { | ||
// debug(data) | ||
}); | ||
|
||
end = new Date | ||
console.log("time = ", end - start, "ms -", COUNT * 1000 / (end - start), " ops/sec") | ||
|