Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Native find vs Lodash find
(version: 3)
Comparing performance of:
Native find with check vs Lodash find vs Native find
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js'></script>
Script Preparation code:
var arr = []; for (let i = 0; i < 10000; i++) { arr.push({ id: i, age: Math.random() * Math.floor(100) }); }
Tests:
Native find with check
!!arr && typeof arr === "array" && arr.find(({age}) => age < 70)
Lodash find
_.find(arr, ({age}) => age < 70)
Native find
arr.find(({age}) => age < 70)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native find with check
Lodash find
Native find
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.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Overview** The test compares three different approaches to finding an element in an array: native JavaScript `find()` method, Lodash's `find()` function, and a native implementation with an additional check. **Native find()** The first approach uses the built-in `find()` method of JavaScript arrays. This method returns the first element in the array that satisfies the provided condition. In this case, the condition is `age < 70`. Pros: * Native code, so it's likely to be fast and efficient. * No external dependencies required. Cons: * The test has an additional check (`!!arr && typeof arr === "array"`), which might incur some overhead due to the extra verification. **Lodash find()** The second approach uses Lodash's `find()` function. This is a popular utility library for functional programming in JavaScript. Pros: * Provides a convenient and concise way to perform array operations. * Often faster than native implementations, especially for complex conditions. Cons: * Requires an external dependency (the Lodash library). * Might incur some overhead due to the need to parse and execute the condition. **Native find() with check** The third approach is similar to the first one but adds an additional check (`!!arr && typeof arr === "array"`). This test case is used to ensure that the native `find()` method behaves correctly even when the array might be null or undefined. Pros: * Allows for verification of the native implementation's behavior. * No external dependencies required. Cons: * The extra check incurs some overhead, as mentioned earlier. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for functional programming, data manipulation, and more. In this case, the `find()` function is used to perform array operations. Lodash is often used in conjunction with other libraries or frameworks to provide additional functionality. **Other alternatives** If you were to reimplement the benchmark without using Lodash, you could consider the following alternatives: * Vanilla JavaScript: You could write a custom implementation of the `find()` method using loops and conditional statements. * Other array functions: Depending on your specific needs, you might consider using other array functions like `some()`, `every()`, or `forEach()` instead of `find()`. * Other libraries: There are many other JavaScript libraries available that provide array operations, such as Ramda or Underscore.js. Keep in mind that these alternatives would likely require more code and might not be as efficient as the native implementation.
Related benchmarks:
lodash vs es6 in find method
lodash vs es6 in find method 2
Unique lodash vs vanilla
Lodash every vs native every test
Comments
Confirm delete:
Do you really want to delete benchmark?