0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 07:00:59 +01:00
nodejs/benchmark/events/ee-emit.js
Brian White 4ba90809ed
events: improve arrayClone performance
PR-URL: https://github.com/nodejs/node/pull/33774
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2020-06-08 15:21:13 -04:00

49 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common.js');
const EventEmitter = require('events').EventEmitter;
const bench = common.createBenchmark(main, {
n: [2e6],
argc: [0, 2, 4, 10],
listeners: [1, 5, 10],
});
function main({ n, argc, listeners }) {
const ee = new EventEmitter();
ee.setMaxListeners(listeners + 1);
for (let k = 0; k < listeners; k += 1)
ee.on('dummy', () => {});
switch (argc) {
case 2:
bench.start();
for (let i = 0; i < n; i += 1) {
ee.emit('dummy', true, 5);
}
bench.end(n);
break;
case 4:
bench.start();
for (let i = 0; i < n; i += 1) {
ee.emit('dummy', true, 5, 10, false);
}
bench.end(n);
break;
case 10:
bench.start();
for (let i = 0; i < n; i += 1) {
ee.emit('dummy', true, 5, 10, false, 5, 'string', true, false, 11, 20);
}
bench.end(n);
break;
default:
bench.start();
for (let i = 0; i < n; i += 1) {
ee.emit('dummy');
}
bench.end(n);
break;
}
}