Script Preparation code:
x
 
function escapeRegExp(string) {
  return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
function replaceAll(str, find, replace) {
  return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
str = "Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test..."
Tests:
  • split and join

     
    str.split("abc").join("def")
  • regex replace

     
    replaceAll(str, 'abc', 'def')
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    split and join
    regex replace

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Chrome 85 on Mac OS X 10.14.6
View result in a separate tab
Test name Executions per second
split and join 1562308.6 Ops/sec
regex replace 608301.6 Ops/sec