Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions benchmark/events/ee-add-once.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var common = require('../common.js');
var events = require('events');

var bench = common.createBenchmark(main, {n: [25e4]});

function main(conf) {
var n = conf.n | 0;

var ee = new events.EventEmitter();
var listeners = [];

for (var k = 0; k < 10; k += 1)
listeners.push(function() {});

ee.setMaxListeners(n * 10);

bench.start();
for (var i = 0; i < n; i += 1) {
for (var k = listeners.length; --k >= 0; /* empty */)
ee.once('dummy', listeners[k]);
}
bench.end(n);
}
File renamed without changes.
23 changes: 23 additions & 0 deletions benchmark/events/ee-emit-mixed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [2e6]});

function main(conf) {
var n = conf.n | 0;

var ee = new EventEmitter();

for (var k = 0; k < 10; k += 1) {
if (k % 2)
ee.once('dummy', function() {});
else
ee.on('dummy', function() {});
}

bench.start();
for (var i = 0; i < n; i += 1) {
ee.emit('dummy');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a very fair benchmark? after all, wouldn't any run after the first run be only to the .on() listeners?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just throwing ideas at the wall, but i'm thinking some sort of Object.freeze() (maybe deep-freeze) on the event emitter, which would (in non-strict mode) i believe silently fail when it is changed, leaving us the same object in each loop - thats the only idea that comes to mind that would only benchmark the .emit(), what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do const objects behave, would that do the job?

}
bench.end(n);
}
24 changes: 24 additions & 0 deletions benchmark/events/ee-emit-multi-args-mixed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [2e6]});

function main(conf) {
var n = conf.n | 0;

var ee = new EventEmitter();
var listeners = [];

for (var k = 0; k < 10; k += 1) {
if (k % 2)
ee.once('dummy', function() {});
else
ee.on('dummy', function() {});
}

bench.start();
for (var i = 0; i < n; i += 1) {
ee.emit('dummy', 5, true);
}
bench.end(n);
}
20 changes: 20 additions & 0 deletions benchmark/events/ee-emit-multi-args-once.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [2e6]});

function main(conf) {
var n = conf.n | 0;

var ee = new EventEmitter();
var listeners = [];

for (var k = 0; k < 10; k += 1)
ee.once('dummy', function() {});

bench.start();
for (var i = 0; i < n; i += 1) {
ee.emit('dummy', 5, true);
}
bench.end(n);
}
File renamed without changes.
20 changes: 20 additions & 0 deletions benchmark/events/ee-emit-once.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var common = require('../common.js');
//var EventEmitter = require('../../lib/events').EventEmitter;
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [2e7]});

function main(conf) {
var n = conf.n | 0;

var ee = new EventEmitter();

for (var k = 0; k < 10; k += 1)
ee.once('dummy', function() {});

bench.start();
for (var i = 0; i < n; i += 1) {
ee.emit('dummy');
}
bench.end(n);
}