Test name | Executions per second |
---|---|
replace regex | 11239362.0 Ops/sec |
replace All | 4573161.0 Ops/sec |
split&join | 14909189.0 Ops/sec |
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
"this {a} is {a} it".replace(/\{a\}/g, "+");
"this {a} is {a} it".replaceAll("{a}", "+");
"this {a} is {a} it".split('{a}').join('+');