Test name | Executions per second |
---|---|
Regular Expression Literal: | 3554038.8 Ops/sec |
split and join | 2090916.0 Ops/sec |
Regular Expression: | 1929565.2 Ops/sec |
while replace | 8713717.0 Ops/sec |
var str = "Test abc test test abc test test test abc test test abc"
str = str.replace(/abc/g, "replaced text");
str = str.split("abc").join("replaced text");
str = str.replace(new RegExp("abc", "g"), "replaced text");
while(str.includes("abc")){
str = str.replace("abc", "replaced text");
}
while(str.indexOf("abc") !== -1){
str = str.replace("abc", "replaced text");
}