Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Find object from array
(version: 0)
Comparing performance of:
using find vs test 2
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
using find
const R = { idA: 12345 }; const RI = { idB: 98765 }; const events = [{ EEI: [{ EEIC: [{ idA: 12345, idB: 98765 }, { idA: 12342, idB: 98715 }, { idA: 12315, idB: 98065 } ] }, { EEIC: [{ idA: 12355, idB: 98065 }, { idA: 12342, idB: 98915 }, { idA: 12915, idB: 90065 } ] } ], enhancements: [] }, { EEI: [{ EEIC: [{ idA: 12341, idB: 98765 }, { idA: 12342, idB: 98715 }, { idA: 12313, idB: 98065 } ] }, { EEIC: [{ idA: 12355, idB: 98065 }, { idA: 12342, idB: 98915 }, { idA: 12915, idB: 90065 } ] } ], enhancements: [] }, { EEI: [{ EEIC: [{ idA: 12345, idB: 98265 }, { idA: 12122, idB: 98745 }, { idA: 12345, idB: 98065 } ] }, { EEIC: [{ idA: 12355, idB: 91065 }, { idA: 12242, idB: 98315 }, { idA: 12925, idB: 90025 } ] } ], enhancements: [{ charges: [{ idA: 11115, idB: 87878 }, { idA: 12342, idB: 98715 }, { idA: 12315, idB: 98065 } ] }, { charges: [{ idA: 12355, idB: 98065 }, { idA: 12342, idB: 98915 }, { idA: 12915, idB: 90065 } ] } ] } ]; if (events && events.length) { let event = events.find(event => { let linkedItem = false; let linkedEnhancement = false; if (event.EEI && event.EEI.length) { for (let item of event.EEI) { linkedItem = item.EEIC && item.EEIC.some(charge => { return charge.idA === Number(R.idA) && charge.idB === Number(RI.idB) }); if (linkedItem) { break; } } } if (!linkedItem && event.enhancements && event.enhancements.length) { for (let enhancement of event.enhancements) { linkedEnhancement = enhancement.charges && enhancement.charges.some(charge => { return charge.idA === Number(R.idA) && charge.idB === Number(RI.idB) }); if (linkedEnhancement) { break; } } } return linkedItem || linkedEnhancement; }); }
test 2
const R = { idA: 12345 }; const RI = { idB: 98765 }; const events = [{ EEI: [{ EEIC: [{ idA: 12345, idB: 98765 }, { idA: 12342, idB: 98715 }, { idA: 12315, idB: 98065 } ] }, { EEIC: [{ idA: 12355, idB: 98065 }, { idA: 12342, idB: 98915 }, { idA: 12915, idB: 90065 } ] } ], enhancements: [] }, { EEI: [{ EEIC: [{ idA: 12341, idB: 98765 }, { idA: 12342, idB: 98715 }, { idA: 12313, idB: 98065 } ] }, { EEIC: [{ idA: 12355, idB: 98065 }, { idA: 12342, idB: 98915 }, { idA: 12915, idB: 90065 } ] } ], enhancements: [] }, { EEI: [{ EEIC: [{ idA: 12345, idB: 98265 }, { idA: 12122, idB: 98745 }, { idA: 12345, idB: 98065 } ] }, { EEIC: [{ idA: 12355, idB: 91065 }, { idA: 12242, idB: 98315 }, { idA: 12925, idB: 90025 } ] } ], enhancements: [{ charges: [{ idA: 11115, idB: 87878 }, { idA: 12342, idB: 98715 }, { idA: 12315, idB: 98065 } ] }, { charges: [{ idA: 12355, idB: 98065 }, { idA: 12342, idB: 98915 }, { idA: 12915, idB: 90065 } ] } ] } ]; if (events && events.length) { event = events.find(event => { let linkedItem = false; let linkedEnhancement = false; if (event.EEI && event.EEI.length) { for (let item of event.EEI) { linkedItem = item.EEIC && item.EEIC.some(charge => { return charge.idA === Number(R.idA) && charge.idB === Number(RI.idB) }); if (linkedItem) { break; } } } if (!linkedItem && event.enhancements && event.enhancements.length) { for (let enhancement of event.enhancements) { linkedEnhancement = enhancement.charges && enhancement.charges.some(charge => { return charge.idA === Number(R.idA) && charge.idB === Number(RI.idB) }); if (linkedEnhancement) { break; } } } return linkedItem || linkedEnhancement; }); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
using find
test 2
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!
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
The code you provided searches for a specific event within a larger array of events. It does this by: 1. **Iterating through each event:** The code first loops through every event in the `events` array. 2. **Checking for matches in EEI and Enhancements:** For each event, it checks if there are matching charges listed within its "EEI" and "enhancements" sections. It compares these charges against a pair of IDs (`R.idA` and `RI.idB`) provided elsewhere. 3. **Using `find()` for efficiency:** The code utilizes the `find()` method, which stops iterating through the array as soon as a matching event is found. 4. **Return value:** If a match is found, the `find()` method returns that specific event object. Otherwise, it returns `undefined`. **Key points:** * **Purpose:** The code aims to efficiently locate an event based on specific charge ID pairs. * **Structure:** It employs nested loops and conditional statements within the `find()` method to achieve this. Let me know if you have any further questions or need clarification on specific parts of the code!
Related benchmarks:
access
Associative object array VS array.find
Find vs FindIndex with object arrays
find in array of objects by field 1002
Array.prototype.find vs Lodash find object
Comments
Confirm delete:
Do you really want to delete benchmark?