mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
29e74d4952
Code in benchmark directory sometimes uses `function () {}` for anonymous callbacks and sometimes uses `() => {}`. Multi-line arrays sometimes have a trailing comma and sometimes do not. Update to always use arrow functions for anonymous callbacks and trailing commas for multiline arrays. PR-URL: https://github.com/nodejs/node/pull/25944 Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
49 lines
1022 B
JavaScript
49 lines
1022 B
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();
|
|
|
|
for (var k = 0; k < listeners; k += 1)
|
|
ee.on('dummy', () => {});
|
|
|
|
var i;
|
|
switch (argc) {
|
|
case 2:
|
|
bench.start();
|
|
for (i = 0; i < n; i += 1) {
|
|
ee.emit('dummy', true, 5);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 4:
|
|
bench.start();
|
|
for (i = 0; i < n; i += 1) {
|
|
ee.emit('dummy', true, 5, 10, false);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 10:
|
|
bench.start();
|
|
for (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 (i = 0; i < n; i += 1) {
|
|
ee.emit('dummy');
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
}
|
|
}
|