Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Loops of loops VS. Manual Loops
(version: 1)
Comparing performance of:
All finds in one loop vs Manual finds with multiple loops
Created:
9 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var size = 1000000; var arr = []; for (var i=0; i < size; i++) { arr.push(i); }
Tests:
All finds in one loop
var index1 = -1; var index2 = -1; var index3 = -1; var index4 = -1; var index5 = -1; for (var ii=0; ii < arr.length; ii++) { if (i === 23423) { index1 = i; } else if (i === 3453) { index2 = i; } else if (i === 9877) { index3 = i; } else if (i === 39248) { index4 = i; } else if (i === 908098) { index5 = i; } }
Manual finds with multiple loops
function findIndex(list, thing) { var foundIndex = -1; for (var i=0; i < list.length; i++) { if (i === thing) { foundIndex = i; } } return foundIndex; } var index1 = findIndex(arr, 23423); var index2 = findIndex(arr, 3453); var index3 = findIndex(arr, 9877); var index4 = findIndex(arr, 39248); var index5 = findIndex(arr, 908098);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
All finds in one loop
Manual finds with multiple loops
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 .push() vs .unshift(), 1M elements
Array .push() vs .unshift(), 100K elements
empty an array in JavaScript - splice vs setting length
empty an array in JavaScript - splice vs setting length. 444 333
Array.push(x) vs array[n]=x
Comments
Confirm delete:
Do you really want to delete benchmark?