hello, I've seen a performance difference depending on whether or not a variable is used in the loop.
let longString = '';
for (let i=0;i<10000000;i++) {
longString += `${i}`;
}
console.log(longString.length);
let cnt = 0;
const st = Date.now();
for (let i=0;i<longString.length - 1;i++) {
if (longString[1] === longString[0]) {
/// if (longString[i] === longString[0]) {
cnt ++;
}
}
console.log(Date.now() - st, cnt);
It is twice as slow with longString[i] than with longString[1].
What optimizations are causing these results?
It doesn't seem to have anything to do with ConsString flattening.