File size: 580 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
let supported: boolean
let perf: Performance

export function isPerformanceSupported() {
  if (supported !== undefined) {
    return supported
  }
  if (typeof window !== 'undefined' && window.performance) {
    supported = true
    perf = window.performance
  }
  else if (typeof globalThis !== 'undefined' && (globalThis as any).perf_hooks?.performance) {
    supported = true
    perf = (globalThis as any).perf_hooks.performance
  }
  else {
    supported = false
  }
  return supported
}

export function now() {
  return isPerformanceSupported() ? perf.now() : Date.now()
}