0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/benchmark/events/ee-add-remove.js
Rich Trott 76e4a74377 benchmark: refactor to eliminate redeclared vars
In order to comply with linting rules used in the rest of the code base,
eliminate redeclared variables. A conservative approach is used so as to
avoid unintentional performance issues (for example, as might be seen in
some situations when using `let` instead of `var`).

PR-URL: https://github.com/nodejs/node/pull/5468
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-03-01 13:48:42 -08:00

26 lines
588 B
JavaScript

'use strict';
var common = require('../common.js');
var events = require('events');
var bench = common.createBenchmark(main, {n: [25e4]});
function main(conf) {
var n = conf.n | 0;
var ee = new events.EventEmitter();
var listeners = [];
var k;
for (k = 0; k < 10; k += 1)
listeners.push(function() {});
bench.start();
for (var i = 0; i < n; i += 1) {
for (k = listeners.length; --k >= 0; /* empty */)
ee.on('dummy', listeners[k]);
for (k = listeners.length; --k >= 0; /* empty */)
ee.removeListener('dummy', listeners[k]);
}
bench.end(n);
}