@exodus/test 1.0.0-rc.104 → 1.0.0-rc.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/benchmark.js +15 -9
package/package.json
CHANGED
package/src/benchmark.js
CHANGED
|
@@ -10,9 +10,10 @@ const fTime = (ns) => {
|
|
|
10
10
|
return min < 5n ? `${s}s` : `${min}min`
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
const { performance, scheduler, process, requestAnimationFrame, gc } = globalThis
|
|
13
14
|
const getTime = (() => {
|
|
14
|
-
if (
|
|
15
|
-
if (
|
|
15
|
+
if (process) return () => process.hrtime.bigint()
|
|
16
|
+
if (performance) return () => BigInt(Math.round(performance.now() * 1e6))
|
|
16
17
|
return () => BigInt(Math.round(Date.now() * 1e6))
|
|
17
18
|
})()
|
|
18
19
|
|
|
@@ -22,9 +23,13 @@ export async function benchmark(name, options, fn) {
|
|
|
22
23
|
if (options?.skip) return
|
|
23
24
|
const { args, timeout = 1000 } = options ?? {}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
// This will pause us for a bit, but we don't care - having a non-busy process is more important
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
28
|
+
if (requestAnimationFrame) await new Promise((resolve) => requestAnimationFrame(resolve))
|
|
29
|
+
if (scheduler?.yield) await scheduler.yield()
|
|
30
|
+
|
|
31
|
+
if (gc) for (let i = 0; i < 4; i++) gc()
|
|
32
|
+
if (!gc && !gcWarned) {
|
|
28
33
|
gcWarned = true
|
|
29
34
|
console.log('Warning: no gc() available\n')
|
|
30
35
|
}
|
|
@@ -43,12 +48,13 @@ export async function benchmark(name, options, fn) {
|
|
|
43
48
|
total += diff
|
|
44
49
|
if (min === undefined || min > diff) min = diff
|
|
45
50
|
if (max === undefined || max < diff) max = diff
|
|
46
|
-
if (total >= BigInt(timeout)) break
|
|
51
|
+
if (total >= BigInt(timeout) * 10n ** 6n) break
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
const mean = total / BigInt(count)
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
let res = `${name} x ${fRps(1e9 / Number(mean))} ops/sec @ ${fTime(mean)}/op`
|
|
56
|
+
if (fTime(min) !== fTime(max)) res += ` (${fTime(min)}..${fTime(max)})`
|
|
57
|
+
console.log(res)
|
|
52
58
|
|
|
53
|
-
if (
|
|
59
|
+
if (gc) for (let i = 0; i < 4; i++) gc()
|
|
54
60
|
}
|