2016-02-20 02:03:16 +01:00
|
|
|
'use strict';
|
2017-09-14 03:48:53 +02:00
|
|
|
const common = require('../common.js');
|
|
|
|
const events = require('events');
|
2014-12-20 00:04:35 +01:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const bench = common.createBenchmark(main, { n: [25e4] });
|
2014-12-20 00:04:35 +01:00
|
|
|
|
|
|
|
function main(conf) {
|
2017-09-14 03:48:53 +02:00
|
|
|
const n = conf.n | 0;
|
2014-12-20 00:04:35 +01:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const ee = new events.EventEmitter();
|
|
|
|
const listeners = [];
|
2014-12-20 00:04:35 +01:00
|
|
|
|
2016-02-28 06:56:18 +01:00
|
|
|
var k;
|
|
|
|
for (k = 0; k < 10; k += 1)
|
2014-12-20 00:04:35 +01:00
|
|
|
listeners.push(function() {});
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
for (var i = 0; i < n; i += 1) {
|
2017-09-14 03:48:53 +02:00
|
|
|
const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
|
2017-07-03 11:52:37 +02:00
|
|
|
for (k = listeners.length; --k >= 0; /* empty */) {
|
|
|
|
ee.on(dummy, listeners[k]);
|
|
|
|
}
|
|
|
|
for (k = listeners.length; --k >= 0; /* empty */) {
|
|
|
|
ee.removeListener(dummy, listeners[k]);
|
|
|
|
}
|
2014-12-20 00:04:35 +01:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|