Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Which is more efficient .replace() or .split().map().join()
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
splitmapjoin
1658277.9 Ops/sec
replace
217946.9 Ops/sec
for
3100714.0 Ops/sec
Script Preparation code:
var testString = '052768194390675213483698521470'; function fakeBin(strNums){ return strNums.split("") .map(num => num = num < 5 ? 0 : 1) .join("") } function fakeBin2(x) { return x.replace(/\d/g, n => "0000011111"[n]) } function fakeBin3(word) { let result = ''; for (var i = 0; i < word.length; i++) { result += Number(word[i]) < 5 ? 0 : 1; } return result; }
Tests:
splitmapjoin
fakeBin(testString)
replace
fakeBin2(testString)
for
fakeBin3(testString)