node/benchmark/perf_hooks/histogram-record.js
James M Snell 1a49193dfb
src: add fast api for Histogram
PR-URL: https://github.com/nodejs/node/pull/51296
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
2023-12-29 16:40:34 +00:00

27 lines
560 B
JavaScript

'use strict';
const assert = require('assert');
const common = require('../common.js');
const { createHistogram } = require('perf_hooks');
const bench = common.createBenchmark(main, {
n: [1e5],
});
function main({ n }) {
const histogram = createHistogram();
bench.start();
for (let i = 0; i < n; i++) {
histogram.record(i + 1);
/* eslint-disable no-unused-expressions */
histogram.max;
histogram.mean;
/* eslint-enable no-unused-expressions */
}
bench.end(n);
// Avoid V8 deadcode (elimination)
assert.ok(histogram);
}