Run details:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Firefox 87
Ubuntu
Desktop
4 years ago
Test name Executions per second
Concat 121.3 Ops/sec
Find & Substring 195.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);
    }