Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Testing methods to iterate array
(version: 0)
Comparing performance of:
Iterate through array once vs Iterate through array twice
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
Iterate through array once
const operation = [ { "op": "replace", "path": "/author/reference", "value": "chewy" }, { "op": "replace", "path": "/status", "value": "completed" }, { "op": "replace", "path": "/subject/reference", "value": "foobar" } ]; let statusOperation = null; let foundItemOperations = null; for (var i = 0, len = operation.length; i < len; i++) { operation[i].path === '/status' ? statusOperation = operation[i] : null; operation[i].path.indexOf('item') !== -1 ? foundItemOperations : null; }
Iterate through array twice
const operation = [ { "op": "replace", "path": "/author/reference", "value": "chewy" }, { "op": "replace", "path": "/status", "value": "completed" }, { "op": "replace", "path": "/subject/reference", "value": "foobar" } ]; const statusOperation = operation.find(op => op.path === '/status'); const foundItemOperations = operation.some((op) => { return op.path.indexOf('item') !== -1; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Iterate through array once
Iterate through array twice
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:
forEach – native or for?
For of VS for VS forEach
compare the ways to generate an empty array for iteration
Array vs Iterators
compare the ways to generate an empty array for iteration 2
Comments
Confirm delete:
Do you really want to delete benchmark?