0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-27 22:16:50 +01:00
nodejs/benchmark/crypto/randomInt.js
Antoine du Hamel 214b00d215
benchmark: add trailing commas in benchmark/crypto
PR-URL: https://github.com/nodejs/node/pull/46553
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2023-02-10 00:54:53 +00:00

39 lines
850 B
JavaScript

'use strict';
const common = require('../common.js');
const { randomInt } = require('crypto');
const bench = common.createBenchmark(main, {
mode: ['sync', 'async-sequential', 'async-parallel'],
min: [-(2 ** 47) + 1, -10_000, -100],
max: [100, 10_000, 2 ** 47],
n: [1e3, 1e5],
});
function main({ mode, min, max, n }) {
if (mode === 'sync') {
bench.start();
for (let i = 0; i < n; i++)
randomInt(min, max);
bench.end(n);
} else if (mode === 'async-sequential') {
bench.start();
(function next(i) {
if (i === n)
return bench.end(n);
randomInt(min, max, () => {
next(i + 1);
});
})(0);
} else {
bench.start();
let done = 0;
for (let i = 0; i < n; i++) {
randomInt(min, max, () => {
if (++done === n)
bench.end(n);
});
}
}
}