node/benchmark/perf_hooks/usertiming.js
Lei Shi 3b758b3287
benchmark: update iterations in benchmark/perf_hooks
Fixes: https://github.com/nodejs/node/issues/50571
PR-URL: https://github.com/nodejs/node/pull/50869
Refs: https://github.com/nodejs/node/issues/50571
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-10 08:49:52 +00:00

35 lines
665 B
JavaScript

'use strict';
const common = require('../common.js');
const {
PerformanceObserver,
performance,
} = require('perf_hooks');
const bench = common.createBenchmark(main, {
n: [1e6],
observe: ['all', 'measure'],
});
function test() {
performance.mark('a');
performance.mark('b');
performance.measure('a to b', 'a', 'b');
}
function main({ n, observe }) {
const entryTypes = observe === 'all' ?
[ 'mark', 'measure' ] :
[ observe ];
const obs = new PerformanceObserver(() => {
bench.end(n);
});
obs.observe({ entryTypes, buffered: true });
bench.start();
performance.mark('start');
for (let i = 0; i < 1e5; i++)
test();
}