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>
37 lines
664 B
JavaScript
37 lines
664 B
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const common = require('../common.js');
|
|
|
|
const {
|
|
PerformanceObserver,
|
|
performance,
|
|
} = require('perf_hooks');
|
|
|
|
function randomFn() {
|
|
return Math.random();
|
|
}
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e6],
|
|
observe: ['function'],
|
|
});
|
|
|
|
let _result;
|
|
|
|
function main({ n, observe }) {
|
|
const obs = new PerformanceObserver(() => {
|
|
bench.end(n);
|
|
});
|
|
obs.observe({ entryTypes: [observe], buffered: true });
|
|
|
|
const timerfied = performance.timerify(randomFn);
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++)
|
|
_result = timerfied();
|
|
|
|
// Avoid V8 deadcode (elimination)
|
|
assert.ok(_result);
|
|
}
|