Test name | Executions per second |
---|---|
replace regex | 4159540.2 Ops/sec |
split-join | 3587522.0 Ops/sec |
replaceAll | 1239270.9 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(" ", "+");