Test name | Executions per second |
---|---|
Memoize typeof call | 451.8 Ops/sec |
Call typeof every time | 480.6 Ops/sec |
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();
}
function getGlobal() {
if (typeof globalThis !== 'undefined' && globalThis) {
return globalThis;
}
}
for (let i = 0; i < 4000; i++) {
const global = getGlobal();
}