0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 15:06:33 +01:00
nodejs/benchmark/events/ee-once.js
Benedikt Meurer 0011eb28cf benchmark: Improve event performance tests.
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>
2017-07-05 13:14:13 +02:00

22 lines
439 B
JavaScript

'use strict';
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;
var bench = common.createBenchmark(main, {n: [2e7]});
function main(conf) {
var n = conf.n | 0;
var ee = new EventEmitter();
function listener() {}
bench.start();
for (var i = 0; i < n; i += 1) {
var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
ee.once(dummy, listener);
ee.emit(dummy);
}
bench.end(n);
}