Currently most of the event tests only test a single event type, which might let those benchmark take fast-paths (in V8) that aren't taken in realistic use cases, and thus the benchmarks are not good proxies of real world uses. PR-URL: https://github.com/nodejs/node/pull/14052 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
28 lines
653 B
JavaScript
28 lines
653 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) {
|
|
var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
|
|
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);
|
|
}
|