From: Jérôme Benoit Date: Sun, 3 Dec 2023 20:25:48 +0000 (+0100) Subject: refactor: cleanup import X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f45b29bff24627d4b57faf90ac038d11044beff3;p=benchmarks-js.git refactor: cleanup import Signed-off-by: Jérôme Benoit --- diff --git a/benchmark-utils.mjs b/benchmark-utils.mjs index 7c7832e..7a681c1 100644 --- a/benchmark-utils.mjs +++ b/benchmark-utils.mjs @@ -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 } /** diff --git a/random.mjs b/random.mjs index 2fff08e..70d48c0 100644 --- a/random.mjs +++ b/random.mjs @@ -1,4 +1,4 @@ -import crypto from 'node:crypto' +import { randomInt } from 'node:crypto' import Benchmark from 'benny' import { secureRandom, @@ -76,9 +76,9 @@ Benchmark.suite( max = Math.floor(max) if (min != null && min !== 0) { min = Math.ceil(min) - return Math.floor(crypto.randomInt(min, max + 1)) + return Math.floor(randomInt(min, max + 1)) } - return Math.floor(crypto.randomInt(max + 1)) + return Math.floor(randomInt(max + 1)) }), Benchmark.add('Math random integer generator', () => { getRandomInteger(maximum) diff --git a/uuid-generator.mjs b/uuid-generator.mjs index f85005f..6ed8015 100644 --- a/uuid-generator.mjs +++ b/uuid-generator.mjs @@ -1,11 +1,11 @@ -import crypto from 'node:crypto' +import { randomUUID } from 'node:crypto' import Benchmark from 'benny' import { v4 as uuid } from 'uuid' Benchmark.suite( 'UUIDv4 generator', Benchmark.add('crypto randomUUID', () => { - crypto.randomUUID() + randomUUID() }), Benchmark.add('uuid', () => { uuid()