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
llama3.1:latest
, generated one year ago):
The code appears to be written in JavaScript and is using the `find()` method to search for an object within an array of objects based on certain conditions. Here's a brief summary: 1. The `events` variable contains an array of objects, each representing an event with various properties (e.g., `EEI`, `enhancements`, etc.). 2. Within each event object, there are arrays or properties that contain additional objects (e.g., `EEIC`, `charges`, etc.). 3. The code uses the `find()` method to search for an event object within the `events` array that meets a specific condition. 4. This condition involves checking if any of the event's properties (`EEI`) or its nested arrays (`enhancements`) contain objects with certain IDs (`idA` and `idB`) matching the values in the `R.idA` and `RI.idB` variables. The code then appears to be using this matched event object to perform some action, although it's not clear from the provided snippet what that action is. Can I help you understand any specific aspect of this code or provide further assistance?
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?