-
-
Save galkin/0bed2a054d4449f72b0ce8f15ef2693e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cachedVar = process.env.MY_ENV_VAR; | |
const cacheObject = structuredClone(process.env); | |
const cached = process.env.MY_ENV_VAR; | |
const loopsCount = 1_000_000; | |
function getEnvVarDirectly() { | |
return process.env.MY_ENV_VAR; | |
} | |
function getEnvVarFromCache() { | |
return cachedVar; | |
} | |
function getEnvVarFromCachedObject() { | |
return cacheObject.MY_ENV_VAR; | |
} | |
console.time('Cached access from object'); | |
for (let i = 0; i < loopsCount; i++) { | |
getEnvVarFromCachedObject(); | |
} | |
console.timeEnd('Cached access from object'); | |
console.time('Cached access from variable'); | |
for (let i = 0; i < loopsCount; i++) { | |
getEnvVarFromCache(); | |
} | |
console.timeEnd('Cached access from variable'); | |
console.time('Direct access'); | |
for (let i = 0; i < loopsCount; i++) { | |
getEnvVarDirectly(); | |
} | |
console.timeEnd('Direct access'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment