Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
multiple test foreach
(version: 0)
Comparing performance of:
forEach imbriqué vs filter vs filter direct push
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var data = []; var res = []; for (let i = 0; i < 150; i++) { data.push({ id: i, bla: 'test', duration: 0 }); } for (let i = 0; i < 150; i++) { res.push({ id: i, firstname: 'lastname', name: 'coucou', times: [] }); } for (var i = data.length - 1; i > 0; i--) { // Generate random number var j = Math.floor(Math.random() * (i + 1)); var temp = data[i]; data[i] = data[j]; data[j] = temp; }
Tests:
forEach imbriqué
res.forEach(oElem => { data.forEach(oShuffle => { if (oElem.id === oShuffle.id) { oElem.times.push(oShuffle); } }); });
filter
res.forEach(oElem => { const aFilter = data.filter(oShuffle => oShuffle.id === oElem.id) || []; aFilter.forEach(oElem => { oElem.times.push(oElem); }); });
filter direct push
res.forEach(oElem => { const aFilter = data.filter(oShuffle => oShuffle.id === oElem.id) || []; oElem.times.push(aFilter); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
forEach imbriqué
filter
filter direct push
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:
For vs For of loop v3
Variable declaration inside or outside for loop (less data 2)
Array entries: For Of, For Loop, .forEach
for vs foreach vs for..of vs for..of over entries random
javascript loops (foreach, for-in, for-of, for, map, reduce) 1000 items
Comments
Confirm delete:
Do you really want to delete benchmark?