Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Some vs Find on objects2
(version: 1)
Comparing performance of:
Find vs Some
Created:
one year ago
by:
Guest
Go to the latest result
Script Preparation code:
const data = [] for (let i = 0; i < 5000; ++i) data.push({ uuid: '69e4b161-0d5d-435f-aa76-51664ed79861', caller_id_name: 'call2sip06408849', caller_id_number: 'Hello', destination_number: '101', from_host: 'call2sip.onlinepbx.ru', to_host: 'pbx2577.test.onpbx.ru', start_stamp: 1672232065, answer_stamp: 1672232065, end_stamp: 1672232076, duration: 11, billsec: 0, user_talk_time: 0, hangup_cause: 'NORMAL_CLEARING', call: { first_uuid: '', channels: {}, }, accountcode: 'inbound', quality_score: 0, blacklist_blocked: false, rec_enabled: true, domains: ['pbx2577.test.onpbx.ru'], gateway: '', origin: 'sip', }) for (let i = 0; i < 1; ++i) data.push({ uuid: '69e4b161-0d5d-435f-aa76-51664ed79861', caller_id_name: 'call2sip06408849', caller_id_number: 'Hi', destination_number: '101', from_host: 'call2sip.onlinepbx.ru', to_host: 'pbx2577.test.onpbx.ru', start_stamp: 1672232065, answer_stamp: 1672232065, end_stamp: 1672232076, duration: 11, billsec: 0, user_talk_time: 0, hangup_cause: 'NORMAL_CLEARING', call: { first_uuid: '', channels: {}, }, accountcode: 'inbound', quality_score: 0, blacklist_blocked: false, rec_enabled: true, domains: ['pbx2577.test.onpbx.ru'], gateway: '', origin: 'sip', })
Tests:
Find
data.find(e => e.caller_id_number === 'Hi')
Some
data.some(e => e.caller_id_number === 'Hi')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Find
Some
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Some
211K/s
Find
209K/s
View exact numbers
Test name
Executions per second
✓
Some
210,687 Ops/sec
Find
208,630 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark presented evaluates the performance of two different JavaScript array methods: `some()` and `find()` on an array of objects representing call records. These methods are used to determine the presence of an element with a specific property value in the array, which in this case relates to the `caller_id_number`. ### Options Compared 1. **Find Method**: - **Code**: `data.find(e => e.caller_id_number === 'Hi')` - **Purpose**: The `find()` method returns the first element in the array that satisfies the provided testing function. If no values satisfy the testing function, it returns `undefined`. - **Use Case**: It's useful when you need to retrieve the actual object that meets a condition. 2. **Some Method**: - **Code**: `data.some(e => e.caller_id_number === 'Hi')` - **Purpose**: The `some()` method tests whether at least one element in the array passes the test implemented by the provided function. It returns `true` or `false`. - **Use Case**: It's beneficial when you only need to check for the existence of an element without requiring the actual object. ### Pros and Cons - **`find()`**: - **Pros**: - Provides the actual matched node/object, which can be further manipulated if needed. - Can retrieve more detailed data if extra properties on the found object are needed. - **Cons**: - Slightly slower in scenarios where only presence needs to be checked, as it does more work (returns a full object versus just a boolean). - **`some()`**: - **Pros**: - Performance benefit when only checking for the existence of a value, as it stops iterating once the first match is found. - Returns a boolean result, which may be simpler for checks. - **Cons**: - Does not provide access to the matched object, so further details may require a separate lookup. ### Performance Considerations The benchmark results indicate that both methods are performant, with `some()` registering approximately 210,687 executions per second and `find()` around 208,630 executions per second. The small difference in speed suggests that while both methods are efficient, `some()` is slightly faster in this context. ### Other Alternatives 1. **Filter**: Using `data.filter(e => e.caller_id_number === 'Hi')` would return an array of all matching objects. This is useful when multiple matches are expected, but it may incur additional performance cost due to the need to create a new array with potentially several matches. 2. **For Loop**: A traditional `for` loop could be used to iterate through the array and find a match manually. This might offer some performance benefits for large datasets, especially if early termination is implemented upon finding the first match, but it sacrifices code readability and conciseness. 3. **Map for Reference**: If the dataset and search queries are large and repetitive, creating a Map from the dataset that allows for quick lookups (i.e., `const map = new Map(data.map(e => [e.caller_id_number, e]))`) and then querying that map can result in faster searches. This approach trades memory for speed. ### Conclusion This benchmark serves as a practical comparison between two common JavaScript functions suited for searching within arrays. The choice between `find()` and `some()` depends on the specific use case—whether the need is to retrieve a full object or simply check for existence. Understanding the use cases and performance characteristics of these methods ensures developers can make informed choices in their JavaScript applications.
Related benchmarks
arr vs indexaction
Spread vs unshift sam
set.add vs array.push vc1
Some vs Find on objects
Comments
Confirm delete:
Do you really want to delete benchmark?