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:
8 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:
4 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
llama3.1:latest
, generated one year ago):
Let's break down what's being tested and the results. **What is being tested?** The benchmark compares two approaches to checking if an element exists in an array: 1. Using the `includes()` method, which is a native JavaScript function (this approach is referred to as "Native" in the test cases). 2. Using the `_includes()` function from the Lodash library. **What options are compared?** We're comparing two different implementations of the `includes` function: * The native `includes()` method built into modern browsers. * The `_includes()` function provided by the Lodash library, a popular utility library for JavaScript. **Pros and cons of each approach:** Native (`includes()`): * Pros: + Built-in to most modern browsers, so it's always available without needing an external library. + Typically faster since it's native code. * Cons: + Not available in older browsers (before ECMAScript 2015, also known as ES6). + May have slightly different behavior or edge cases compared to Lodash. Lodash (`_includes()`): * Pros: + Backwards compatible with older browsers that don't support `includes()`. + Well-tested and widely used in the JavaScript community. * Cons: + Adds an external library dependency, which can increase bundle size and complexity. + May be slightly slower than the native implementation due to the overhead of a function call. **Library: Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functions for tasks like array manipulation, string formatting, and more. In this case, we're using the `_includes()` function from Lodash to perform the same task as the native `includes()` method. **JavaScript feature or syntax: None** There's no special JavaScript feature or syntax being used in this benchmark. The code is straightforward and uses standard JavaScript methods and functions. **Other alternatives:** If you need to check if an element exists in an array across different browsers, you could consider using: * A polyfill for the `includes()` method, which would provide a compatible implementation for older browsers. * Other utility libraries like Underscore.js or Ramda.js, which also offer similar functions for array manipulation. However, for most modern use cases, the native `includes()` method is a good choice, and Lodash's `_includes()` function can be used as a fallback for compatibility with older browsers.
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?