2016-02-20 02:03:16 +01:00
|
|
|
'use strict';
|
2017-09-14 03:48:53 +02:00
|
|
|
const common = require('../common.js');
|
|
|
|
const EventEmitter = require('events').EventEmitter;
|
2015-02-05 21:26:28 +01:00
|
|
|
|
2017-11-07 19:22:49 +01:00
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
n: [2e6],
|
|
|
|
argc: [0, 2, 4, 10],
|
|
|
|
listeners: [1, 5, 10],
|
|
|
|
});
|
2015-02-05 21:26:28 +01:00
|
|
|
|
2017-12-30 03:59:37 +01:00
|
|
|
function main({ n, argc, listeners }) {
|
2017-09-14 03:48:53 +02:00
|
|
|
const ee = new EventEmitter();
|
2020-06-06 20:18:46 +02:00
|
|
|
ee.setMaxListeners(listeners + 1);
|
2015-02-05 21:26:28 +01:00
|
|
|
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let k = 0; k < listeners; k += 1)
|
2019-02-05 07:06:08 +01:00
|
|
|
ee.on('dummy', () => {});
|
2015-02-05 21:26:28 +01:00
|
|
|
|
2017-11-07 19:22:49 +01:00
|
|
|
switch (argc) {
|
|
|
|
case 2:
|
|
|
|
bench.start();
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let i = 0; i < n; i += 1) {
|
2017-11-07 19:22:49 +01:00
|
|
|
ee.emit('dummy', true, 5);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
bench.start();
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let i = 0; i < n; i += 1) {
|
2017-11-07 19:22:49 +01:00
|
|
|
ee.emit('dummy', true, 5, 10, false);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
bench.start();
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let i = 0; i < n; i += 1) {
|
2017-11-07 19:22:49 +01:00
|
|
|
ee.emit('dummy', true, 5, 10, false, 5, 'string', true, false, 11, 20);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bench.start();
|
2020-01-24 18:12:49 +01:00
|
|
|
for (let i = 0; i < n; i += 1) {
|
2017-11-07 19:22:49 +01:00
|
|
|
ee.emit('dummy');
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
2015-02-05 21:26:28 +01:00
|
|
|
}
|
|
|
|
}
|