Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Sort benchmark
(version: 0)
Comparing performance of:
FILTER vs FOR vs FOR_EACH
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.presetSortArray = Array.from(Array(50).keys()).map(i => ([1, 3].includes((i + 1) % 7) ? i * -1 : (i + 1) * 7))
Tests:
FILTER
const result = window.presetSortArray.filter(element => element < 0).concat(window.presetSortArray.filter(element => element >= 0))
FOR
const resultArrayFirstPart = new Array(window.presetSortArray.length) const resultArraySecondPart = new Array(window.presetSortArray.length) let index1 = 0; let index2 = 0; for (let index = 0, length = window.presetSortArray?.length; index < length; ++index) { if (window.presetSortArray[index] <= 0) { resultArrayFirstPart[++window.index1] = window.presetSortArray[index]; } else { resultArraySecondPart[++window.index2] = window.presetSortArray[index]; } } for (let index = 0; index < window.index2; ++index) { resultArrayFirstPart[++window.index1] = window.resultArraySecondPart[index]; } const result = resultArrayFirstPart
FOR_EACH
const resultArrayFirstPart = [] const resultArraySecondPart = [] window.presetSortArray.forEach(element => { if (element <= 0) { resultArrayFirstPart.push(element) } else { resultArraySecondPart.push(element) } }) const result = resultArrayFirstPart.concat(resultArraySecondPart)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
FILTER
FOR
FOR_EACH
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:
Array Sorting Methods
Sorting speed comparison
pre-sorted sorting (int vs obj)
Sort benchmark 2
Comments
Confirm delete:
Do you really want to delete benchmark?