-
-
Save Connormiha/83ab13e08fa8769336253c085b437311 to your computer and use it in GitHub Desktop.
Check speed reading process.env
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 random = Math.random(); | |
let res = 0; | |
let TT = '2'; | |
let TT2 = '3'; | |
// To avoid JIT optimization for varible 'let TT' | |
let timer = setTimeout(() => { | |
TT = String(Math.random()); | |
TT2 = String(Math.random()); | |
}, 1000); | |
console.time('With env'); | |
for (let i = 0;i < 20000; i++) { | |
if (process.env.TT !== '1' && process.env.TT2 !== '10') { | |
res += random; | |
} | |
}; | |
console.timeEnd('With env'); | |
console.time('With cache env'); | |
for (let i = 0;i < 20000; i++) { | |
if (TT !== '1' && TT2 !== '10') { | |
res += random; | |
} | |
}; | |
console.timeEnd('With cache env'); | |
// Show result to avoid JIT optimization for calculation res | |
console.log(res); | |
clearTimeout(timer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment