diff --git a/benchmark/events/ee-emit-multi-args.js b/benchmark/events/ee-emit-multi-args.js new file mode 100644 index 00000000000000..7e05a305085311 --- /dev/null +++ b/benchmark/events/ee-emit-multi-args.js @@ -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); +} diff --git a/benchmark/events/ee-emit.js b/benchmark/events/ee-emit.js new file mode 100644 index 00000000000000..b3a3d2ab0bfcc3 --- /dev/null +++ b/benchmark/events/ee-emit.js @@ -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); +} diff --git a/benchmark/events/ee-listener-count.js b/benchmark/events/ee-listener-count.js new file mode 100644 index 00000000000000..83862782154a88 --- /dev/null +++ b/benchmark/events/ee-listener-count.js @@ -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); +} diff --git a/benchmark/events/ee-listeners-many.js b/benchmark/events/ee-listeners-many.js new file mode 100644 index 00000000000000..dc6b7db66fa9df --- /dev/null +++ b/benchmark/events/ee-listeners-many.js @@ -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); +} diff --git a/benchmark/events/ee-listeners.js b/benchmark/events/ee-listeners.js new file mode 100644 index 00000000000000..6bd0acf53bb7af --- /dev/null +++ b/benchmark/events/ee-listeners.js @@ -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); +}