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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
splitmapjoin
942551.8 Ops/sec
replace
485762.8 Ops/sec
for
201378.7 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)