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