Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
fake-binary
(version: 0)
Tests the efficiency between using .replace() and .split().map().join() to edit single character values in a string that only contains numbers.
Comparing performance of:
Conversion vs Replacement vs Loop
Created:
8 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
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(x) { var result = ""; for (var i = 0; i < x.length; i++) { if (x.charCodeAt(i) < 53) { result += "0"; } else { result += "1"; } } return result; }
Tests:
Conversion
fakeBin("123456789")
Replacement
fakeBin2("123456789")
Loop
fakeBin3("123456789")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Conversion
Replacement
Loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Which is more efficient .replace() or .split().map().join()
fake-binary
alpha-numeric string
Testing character counting
Comments
Confirm delete:
Do you really want to delete benchmark?