repositories
/
benchmarks-js.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: cleanup import
[benchmarks-js.git]
/
benchmark-utils.mjs
diff --git
a/benchmark-utils.mjs
b/benchmark-utils.mjs
index 202a9a08ac4eb42f79f975e23b0f00f03fc1d9e7..7a681c138877d9d6324333ad7197978864f5c036 100644
(file)
--- a/
benchmark-utils.mjs
+++ b/
benchmark-utils.mjs
@@
-1,19
+1,19
@@
-import
crypto from '
crypto'
+import
{ randomBytes, getRandomValues } from 'node:
crypto'
/**
* Generate a cryptographically secure random number in the [0,1[ range
* @returns
*/
export function secureRandom () {
/**
* 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
}
/**
}
/**
- *
Generate a cryptographically secure random number in the [0,1[ range
+ * Generate a cryptographically secure random number in the [0,1[ range
* @returns
*/
export function secureRandomWithRandomValues () {
* @returns
*/
export function secureRandomWithRandomValues () {
- return
crypto.
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')
}
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) {
* @returns
*/
export async function sleep (ms) {
- return
new Promise((resolve)
=> setTimeout(resolve, ms))
+ return
await new Promise(resolve
=> setTimeout(resolve, ms))
}
}