Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Some vs Find on objects
(version: 1)
Comparing performance of:
Find vs Some
Created:
one year ago
by:
Guest
Jump 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', }) data.push({ username: 'titi' }) for (let i = 0; i < 2500; ++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
Test name
Executions per second
Find
112797.8 Ops/sec
Some
106589.3 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark provided compares two different approaches for searching through an array of objects in JavaScript: using `Array.prototype.find()` and `Array.prototype.some()`. Both methods are commonly used to search through data structures, but they have different purposes and performance characteristics, which is what this benchmark aims to highlight. ### Benchmark Options Compared 1. **`find` Method**: - **Definition**: The `find` method searches through the array and returns the first element that satisfies the provided testing function. If no values satisfy the testing function, it returns `undefined`. - **Usage**: `data.find(e => e.caller_id_number === 'Hi')` - **Pros**: - Returns the actual object that matches the condition, which is useful if you need to work with that entity further. - Intuitive for retrieving specific data based on a condition. - **Cons**: - May have a slightly higher overhead because it must continue checking each element until it finds a match, even if further matches might exist. 2. **`some` Method**: - **Definition**: The `some` method tests whether at least one element in the array passes the test implemented by the provided function. It returns a boolean value (`true` or `false`). - **Usage**: `data.some(e => e.caller_id_number === 'Hi')` - **Pros**: - Generally more performant in scenarios where you only need to check for the existence of at least one match, as it stops searching as soon as it finds the first valid element. - Useful for assertions or conditions where the matched element itself is irrelevant. - **Cons**: - Does not provide the matched object itself, which could lead to additional code if you need both the existence check and the object later. ### Additional Considerations - **Performance**: The benchmark results show the number of executions per second for each method: - `find` executed approximately **112,797 times per second**. - `some` executed approximately **106,589 times per second**. The results indicate that although `find` appears to be slightly faster in this test case, actual performance can depend on a variety of factors, such as the structure and size of the data, browser optimizations, and specific implementations. - **Alternatives**: Other options to consider for searching through arrays include: - **`filter`**: This method creates a new array with all elements that pass the test implemented by the provided function. It can be useful when you want to get all matching elements rather than just the first one. - **`forEach`**: This method allows for executing a function for each element in the array. However, it does not return any value and is less optimal for searching purposes. - **Use Cases**: The choice between `find` and `some` should be driven by the specific requirements of the task: - Use `find` if you need the actual object and plan to manipulate or inspect it. - Use `some` if the existence of a condition is sufficient for your logic, leading to potential performance benefits. In summary, understanding the purpose of each method and the context in which they are used will help software engineers optimize their code effectively based on the needs of their applications.
Related benchmarks:
find vs some - hvad er hurtigst?
push vs spread v3
push VS destructuration
kmionnomij
Pusshhhhh
Testyyrt
arr vs indexaction
set.add vs array.push vc1
Some vs Find on objects2
Comments
Confirm delete:
Do you really want to delete benchmark?