Test name | Executions per second |
---|---|
replace regex | 10831646.0 Ops/sec |
replace All | 3220659.5 Ops/sec |
replace regex 2 | 9049003.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".replaceAll(" ", "+");
"this is it".replace(/\s+/g, "+");