Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.includes vs includes()
(version: 0)
Comparing performance of:
Lodash vs Native
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var data = ['mustafa', 'kemal', 'atatürk'];
Tests:
Lodash
_.includes(data, 'kemal');
Native
data.includes('kemal');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser/OS:
Chrome 144 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
45968348.0 Ops/sec
Native
181779312.0 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark compares the performance of two methods for checking if an item exists within an array: * **`_.includes(data, 'kemal')`:** This uses the `includes()` function from the Lodash library. Lodash is a popular JavaScript utility library that provides many helpful functions beyond what's built into vanilla JavaScript. * **`data.includes('kemal')`:** This uses the native `includes()` method available in modern JavaScript browsers. **Pros and Cons:** * **Lodash:** * **Pros:** Offers a consistent and well-tested implementation across different environments, potentially more performant than older browser implementations. * **Cons:** Adds an extra dependency to your project (Lodash library). Can lead to larger bundle sizes if not carefully managed. * **Native `includes()`:** * **Pros:** No additional dependencies. More lightweight and directly integrated with JavaScript. Usually optimized for modern browsers. * **Cons:** May have varying performance across older browsers that don't fully support it. **Considerations:** * **Project Requirements:** If your project already relies on Lodash for other functionalities, using `_.includes()` might be convenient and consistent. However, if Lodash isn't used elsewhere, adding it solely for this purpose might not be ideal. * **Performance Impact:** The benchmark results show that the native `includes()` method is significantly faster in this particular case. * **Browser Support:** Native `includes()` has good support in modern browsers. **Alternatives:** While less common due to better efficiency, you could explore: * **Manual Iteration:** Looping through the array yourself with a conditional check (`for` loop or `while` loop). This offers more control but can be significantly slower than both `includes()` methods. Let me know if you have any other questions about JavaScript benchmarks or this specific example!
Related benchmarks:
_.includes vs includes() vs indexof
IndexOf vs Includes vs lodash includes for string
Lodash@4.17.21 includes vs native includes
_.includes vs includes() 2
Comments
Confirm delete:
Do you really want to delete benchmark?