Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native find vs underscore _.find
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs _.find
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.3/underscore-min.js"></script>
Script Preparation code:
var users = [ { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
array find
// Native users.find(function (o) { return o.age < 40; })
_.find
_.find(users, function (o) { return o.age < 40; })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array find
_.find
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:148.0) Gecko/20100101 Firefox/148.0
Browser/OS:
Firefox 148 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find
1255621888.0 Ops/sec
_.find
33130194.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark JSON and explain what is tested, compared, and their pros and cons. **Benchmark Definition** The benchmark tests two approaches to find an element in an array: 1. **Native Find**: Using the `find()` method on the native JavaScript array object. 2. **Underscore _.find**: Using the `_.find()` function from the Underscore.js library. **Script Preparation Code** The script preparation code defines a sample array of objects: `users` with three elements, each containing an `age` property. **Html Preparation Code** The HTML preparation code includes a script tag that loads the Underscore.js library (version 1.13.3). **Individual Test Cases** There are two test cases: 1. **array find**: This test case uses the native JavaScript array object and calls the `find()` method on it, passing a callback function that returns `true` if the `age` property is less than 40. 2. **_.find**: This test case uses the Underscore.js library and calls the `_.find()` function on the `users` array, passing a callback function that returns `true` if the `age` property is less than 40. **Pros and Cons of Each Approach** 1. **Native Find** * Pros: + Lightweight and efficient + No additional library dependencies + Suitable for most use cases * Cons: + May not work well with large arrays or complex data structures + Callback function can be slower than a pure function call 2. **Underscore _.find** * Pros: + Can handle larger arrays and more complex data structures + Uses a pure function call, which can be faster than callback-based implementations * Cons: + Requires an additional library dependency (Underscore.js) + May add overhead due to the library's presence **Other Considerations** 1. **ES6 Spread Operator** Although not directly tested in this benchmark, it's worth noting that some test cases might use the ES6 spread operator (`...`) to create a shallow copy of the array. This could potentially affect performance. 2. **Device and Browser Variability** The benchmark results are specific to a Chrome 116 browser on a Mac OS X 10.15.7 device. Other devices, browsers, or environments might exhibit different performance characteristics. **Alternatives** Some alternative approaches that could be tested in this benchmark include: 1. Using `Array.prototype.findIndex()` instead of `find()` 2. Implementing a custom search algorithm using a data structure like a binary search tree 3. Testing the performance of a library like Lodash or Ramda By testing these alternatives, developers can gain a better understanding of the trade-offs and optimizations involved in finding elements in arrays.
Related benchmarks:
native find vs lodash _.find
native find vs lodash _.find hey joe
native find vs for..in
native find vs underscore _.find asdfasdf
Comments
Confirm delete:
Do you really want to delete benchmark?