X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmark-utils.mjs;h=7a681c138877d9d6324333ad7197978864f5c036;hb=1b1a9b5472efafd1a8447a68ea365396c1647301;hp=e914e6b20337bf26b8aa58a8e4017ea834458fc8;hpb=f913c68ce1ad111704f1f319706cb99e9659e236;p=benchmarks-js.git diff --git a/benchmark-utils.mjs b/benchmark-utils.mjs index e914e6b..7a681c1 100644 --- a/benchmark-utils.mjs +++ b/benchmark-utils.mjs @@ -1,11 +1,11 @@ -import crypto, { webcrypto } from 'crypto' +import { randomBytes, getRandomValues } from 'node:crypto' /** * Generate a cryptographically secure random number in the [0,1[ range * @returns */ export function secureRandom () { - return crypto.randomBytes(4).readUInt32LE() / 0x100000000 + return randomBytes(4).readUInt32LE() / 0x100000000 } /** @@ -13,7 +13,7 @@ export function secureRandom () { * @returns */ export function secureRandomWithRandomValues () { - return webcrypto.getRandomValues(new Uint32Array(1))[0] / 0x100000000 + return getRandomValues(new Uint32Array(1))[0] / 0x100000000 } /** @@ -46,7 +46,7 @@ export function generateRandomFloat (max = Number.MAX_VALUE, min = 0) { if (max - min === Infinity) { throw new RangeError('Invalid interval') } - return (crypto.randomBytes(4).readUInt32LE() / 0xffffffff) * (max - min) + min + return (randomBytes(4).readUInt32LE() / 0xffffffff) * (max - min) + min } /** @@ -93,5 +93,5 @@ export function generateRandomObject ( * @returns */ export async function sleep (ms) { - return new Promise(resolve => setTimeout(resolve, ms)) + return await new Promise(resolve => setTimeout(resolve, ms)) }