string replaceAll test
Date tested:
4 years ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Test name
Executions per second
split and join
1562308.6 Ops/sec
regex replace
608301.6 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
function escapeRegExp(string) { return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } function replaceAll(str, find, replace) { return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); } str = "Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test..."
Tests:
split and join
str.split("abc").join("def")
regex replace
replaceAll(str, 'abc', 'def')
Open this result on MeasureThat.net