Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native find() vs lodash _.find() vs native some()
(version: 0)
Comparing performance of:
array find() vs _.find() vs _.some()
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/lodash.js/4.17.11/lodash.core.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(u => u.age < 40)
_.find()
_.find(users, (u) => u.age < 40)
_.some()
// Native users.some(u => u.age < 40)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
array find()
_.find()
_.some()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find()
16571206.0 Ops/sec
_.find()
5587680.5 Ops/sec
_.some()
16586684.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** The provided JSON represents a JavaScript benchmarking test on MeasureThat.net, comparing the performance of native JavaScript functions (`Array.prototype.find()` and `Array.prototype.some()`) against those from the popular utility library Lodash (`_.find()` and `_some()`). **Benchmarked Functions** 1. **Native `Array.prototype.find()`**: This function searches for the first element in an array that satisfies a specified condition. 2. **Lodash _.find()**: This is a higher-order function that takes two arguments: an array and a callback function. It returns the first element of the array that matches the condition provided by the callback. 3. **Native `Array.prototype.some()`**: This function checks if at least one element in an array satisfies a specified condition. 4. **Lodash _.some()**: Similar to Lodash's `_find()`, but instead of returning a single value, it returns a boolean indicating whether any element matches the condition. **Comparison Options** The benchmark compares these four functions: * Native JavaScript (`Array.prototype.find()` and `Array.prototype.some()`) * Lodash (`_.find()` and `_some()`) **Pros and Cons** **Native JavaScript Functions** Pros: * Typically faster since they are implemented in native code, optimized for performance. * Less memory usage compared to Lodash implementations. Cons: * Less readable due to lack of clear variable names and callback function complexity. * May not be compatible with older browsers or environments that don't support modern JavaScript features. **Lodash Functions** Pros: * More readable due to the use of named functions and clear variable names. * Compatible with a wider range of browsers and environments, as Lodash provides polyfills for legacy JavaScript features. Cons: * Typically slower since they involve function call overhead and additional memory usage. * May not be optimized for performance in all scenarios. **Other Considerations** * The benchmark uses an array of objects with nested properties to test the functions' ability to traverse complex data structures. * The Lodash implementation uses a closure-based approach, while native JavaScript implementations rely on the Array.prototype methods directly. **Library Overview (Lodash)** Lodash is a popular utility library that provides a comprehensive set of functional programming helpers for JavaScript. Its `_find()` and `_some()` functions are designed to simplify common data manipulation tasks, making code more readable and maintainable. **Special JS Feature/ Syntax** None mentioned in the provided benchmark. **Alternatives** If you're interested in exploring alternative JavaScript libraries or native implementations, consider: * Other utility libraries like Moment.js for date manipulation or Knex.js for database interactions. * Native JavaScript alternatives to Lodash functions, such as `Array.prototype.filter()` and `Array.prototype.some()` (although these may not be as concise or readable). * Browser-specific polyfills or transpilers to target older environments. I hope this explanation helps you understand the benchmark's context and the trade-offs between native JavaScript functions and Lodash implementations!
Related benchmarks:
lodash find vs native find by id
Array find vs lodash _.find
native find vs lodash _.find equal
native find vs lodash _.find for objects equality
Comments
Confirm delete:
Do you really want to delete benchmark?