perf_hooks: reduce overhead of createHistogram

PR-URL: https://github.com/nodejs/node/pull/50074
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Vinícius Lourenço 2023-10-05 21:39:55 -03:00 committed by Node.js GitHub Bot
parent 8e814e3b82
commit adaef03216
3 changed files with 82 additions and 20 deletions

View file

@ -0,0 +1,22 @@
'use strict';
const assert = require('assert');
const common = require('../common.js');
const { createHistogram } = require('perf_hooks');
const bench = common.createBenchmark(main, {
n: [1e5],
});
let _histogram;
function main({ n }) {
bench.start();
for (let i = 0; i < n; i++)
_histogram = createHistogram();
bench.end(n);
// Avoid V8 deadcode (elimination)
assert.ok(_histogram);
}