Tests:
  • Memoize typeof call

    x
     
    let cachedGlobal;
    function getGlobal() {
      if (cachedGlobal) {
        return cachedGlobal;
      }
      
      if (typeof globalThis !== 'undefined' && globalThis) {
        cachedGlobal = globalThis;
      }
      
      return cachedGlobal
    }
    for (let i = 0; i < 4000; i++) {
      const global = getGlobal();
    }
  • Call typeof every time

     
    function getGlobal() {
      if (typeof globalThis !== 'undefined' && globalThis) {
        return globalThis;
      }
    }
    for (let i = 0; i < 4000; i++) {
      const global = getGlobal();
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Memoize typeof call
    Call typeof every time

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 months ago)
Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0
Firefox 89 on Linux
View result in a separate tab
Test name Executions per second
Memoize typeof call 451.8 Ops/sec
Call typeof every time 480.6 Ops/sec