0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 07:00:59 +01:00
nodejs/benchmark/events/eventtarget.js
James M Snell 785842a053 events: initial implementation of experimental EventTarget
See documentation changes for details

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/33556
Refs: https://github.com/nodejs/node/pull/33527
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
2020-05-28 06:31:58 -07:00

25 lines
539 B
JavaScript

'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [2e7],
listeners: [1, 5, 10]
}, { flags: ['--expose-internals'] });
function main({ n, listeners }) {
const { EventTarget, Event } = require('internal/event_target');
const target = new EventTarget();
for (let n = 0; n < listeners; n++)
target.addEventListener('foo', () => {});
const event = new Event('foo');
bench.start();
for (let i = 0; i < n; i++) {
target.dispatchEvent(event);
}
bench.end(n);
}