From f45b29bff24627d4b57faf90ac038d11044beff3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 3 Dec 2023 21:25:48 +0100 Subject: [PATCH] refactor: cleanup import MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmark-utils.mjs | 2 +- random.mjs | 6 +++--- uuid-generator.mjs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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() -- 2.34.1