@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/benchmark.js +15 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/test",
3
- "version": "1.0.0-rc.104",
3
+ "version": "1.0.0-rc.105",
4
4
  "author": "Exodus Movement, Inc.",
5
5
  "description": "A test suite runner",
6
6
  "homepage": "https://github.com/ExodusMovement/test",
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 (globalThis.process) return () => process.hrtime.bigint()
15
- if (globalThis.performance) return () => BigInt(Math.round(performance.now() * 1e6))
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
- if (globalThis.gc) {
26
- for (let i = 0; i < 4; i++) globalThis.gc()
27
- } else if (!gcWarned) {
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
- const rps = 1e9 / Number(mean)
51
- console.log(`${name} x ${fRps(rps)} ops/sec @ ${fTime(mean)}/op (${fTime(min)}..${fTime(max)})`)
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 (globalThis.gc) for (let i = 0; i < 4; i++) globalThis.gc()
59
+ if (gc) for (let i = 0; i < 4; i++) gc()
54
60
  }