Skip to content

Commit

Permalink
benchmark: add more EventEmitter benchmarks
Browse files Browse the repository at this point in the history
PR-URL: #730
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Brendan Ashworth <[email protected]>
  • Loading branch information
mscdex authored and bnoordhuis committed Feb 6, 2015
1 parent 96597bc commit 847b9d2
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
20 changes: 20 additions & 0 deletions benchmark/events/ee-emit-multi-args.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: [25e4]});

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

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

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

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

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

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

var ee = new EventEmitter();

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

bench.start();
for (var i = 0; i < n; i += 1) {
ee.emit('dummy');
}
bench.end(n);
}
20 changes: 20 additions & 0 deletions benchmark/events/ee-listener-count.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: [25e4]});

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

var ee = new EventEmitter();
var listenerCount = EventEmitter.listenerCount;

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

bench.start();
for (var i = 0; i < n; i += 1) {
var r = listenerCount(ee, 'dummy');
}
bench.end(n);
}
20 changes: 20 additions & 0 deletions benchmark/events/ee-listeners-many.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: [25e4]});

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

var ee = new EventEmitter();
ee.setMaxListeners(101);

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

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

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

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

var ee = new EventEmitter();

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

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

0 comments on commit 847b9d2

Please sign in to comment.