Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Chrome 120
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
replace regex 11239362.0 Ops/sec
replace All 4573161.0 Ops/sec
split&join 14909189.0 Ops/sec
Script Preparation code:
AخA
 
String.prototype.replaceAll = function(search, replacement) {
    var target = this;
    return target.replace(new RegExp(search, 'g'), replacement);
};
Tests:
  • replace regex

     
    "this {a} is {a} it".replace(/\{a\}/g, "+");
  • replace All

     
    "this {a} is {a} it".replaceAll("{a}", "+");
  • split&join

     
    "this {a} is {a} it".split('{a}').join('+');