Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Chrome 103
Mac OS X 10.15.7
Desktop
2 years ago
Test name Executions per second
for 24.1 Ops/sec
for ... of 15.8 Ops/sec
Script Preparation code:
AخA
 
const text = new Array(2000000).fill("a").join("");
Tests:
  • for

     
    const text = new Array(2000000).fill("a").join("");
    const string = new Array(text.length);
    for (let i = 0; i < text.length; i++) {
      string[i] = text[i];
    }
  • for ... of

     
    const text = new Array(2000000).fill("a").join("");
    const string = [];
    for (const char of text) {
      string.push(char);
    }