Skip to content

Instantly share code, notes, and snippets.

@Connormiha
Created August 27, 2023 17:05
Show Gist options
  • Save Connormiha/83ab13e08fa8769336253c085b437311 to your computer and use it in GitHub Desktop.
Save Connormiha/83ab13e08fa8769336253c085b437311 to your computer and use it in GitHub Desktop.
Check speed reading process.env
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