mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
3b758b3287
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>
35 lines
665 B
JavaScript
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();
|
|
}
|