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
|
|
|
|
2018-05-01 13:32:10 +02:00
|
|
|
const bench = common.createBenchmark(main, { n: [1e6] });
|
2014-12-20 00:04:35 +01:00
|
|
|
|
2017-12-30 03:59:37 +01:00
|
|
|
function main({ n }) {
|
2017-09-14 03:48:53 +02:00
|
|
|
const ee = new events.EventEmitter();
|
|
|
|
const listeners = [];
|
2014-12-20 00:04:35 +01:00
|
|
|
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let k = 0; k < 10; k += 1)
|
2019-02-05 07:06:08 +01:00
|
|
|
listeners.push(() => {});
|
2014-12-20 00:04:35 +01:00
|
|
|
|
|
|
|
bench.start();
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let i = 0; i < n; i += 1) {
|
2017-09-14 03:48:53 +02:00
|
|
|
const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let k = listeners.length; --k >= 0; /* empty */) {
|
2017-07-03 11:52:37 +02:00
|
|
|
ee.on(dummy, listeners[k]);
|
|
|
|
}
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let k = listeners.length; --k >= 0; /* empty */) {
|
2017-07-03 11:52:37 +02:00
|
|
|
ee.removeListener(dummy, listeners[k]);
|
|
|
|
}
|
2014-12-20 00:04:35 +01:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|