Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Chrome 117
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Concat 27.3 Ops/sec
Find & Substring 41.2 Ops/sec
Script Preparation code:
AخA
 
var string = "HelloWorld!".repeat(100) + " Hi";
Tests:
  • Concat

     
    for (let i = 0; i < 200; ++i) {
      let result = '';
      for (let j = 0; j < string.length; ++j) {
        if (' ' === string[j]) {
          break;
        }
        result += string[j];
      }
    }
  • Find & Substring

     
    for (let i = 0; i < 200; ++i) {
      let j;
      for (j = 0; j < string.length; ++j) {
        if (' ' === string[j]) {
          break;
        }
      }
      let result = string.substring(0, j);
    }