Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash includes vs includes vs indexof
(version: 0)
Comparing performance of:
lodash includes vs indexof vs ECMA 7 includes
Created:
7 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.11/lodash.js"></script>
Script Preparation code:
var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
Tests:
lodash includes
_.includes(a, 16)
indexof
a.indexOf(16) !== -1
ECMA 7 includes
a.includes(16)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash includes
indexof
ECMA 7 includes
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/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash includes
12846579.0 Ops/sec
indexof
34250060.0 Ops/sec
ECMA 7 includes
34485916.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **Benchmark Overview** The provided benchmark compares three different approaches to check if an element exists in an array: using `_.includes` from Lodash, using the `indexOf` method, and using the new ECMA 7 `includes` syntax. **Options Compared** 1. **Lodash `.includes`**: This is a higher-order function that checks if a value exists in an array. It takes two arguments: the value to search for and the array to search in. 2. **Index of (`indexOf`) method**: This method returns the index of the first occurrence of a value in an array, or -1 if the value is not found. 3. **ECMA 7 `includes` syntax**: This syntax has been introduced in ECMAScript 2019 (ES2020) and allows you to use the `includes` method on arrays. **Pros and Cons** * **Lodash `.includes`**: + Pros: Higher-order function, can handle multiple values, easy to read and understand. + Cons: Requires an additional library, slower than native methods. * **Index of (`indexOf`) method**: + Pros: Fastest method, no additional libraries required. + Cons: Can be slower for large arrays, may throw errors if the value is not found. * **ECMA 7 `includes` syntax**: + Pros: Native implementation, fast, easy to read and understand. + Cons: Requires modern browsers or Node.js environments. **Library and Syntax** The benchmark uses Lodash, a popular utility library for JavaScript. The `_` symbol is an alias for the Lodash root object, which provides access to various functions and methods. The ECMA 7 `includes` syntax has been introduced in ECMAScript 2019 (ES2020) and allows you to use the `includes` method on arrays. This syntax is supported by modern browsers and Node.js environments. **Special JS Features** There are no special JavaScript features or syntaxes used in this benchmark. **Other Alternatives** If you need to check if an element exists in an array, other alternatives include: * Using a for loop with the `in` operator: `for (var i = 0; i < arr.length; i++) { if (arr[i] === value) break; }` * Using the `Array.prototype.includes()` method (introduced in ECMAScript 2015/ES6): `arr.includes(value)` * Using a third-party library like jQuery's `inArray()` function. Keep in mind that these alternatives may have different performance characteristics and trade-offs compared to using Lodash or the ECMA 7 `includes` syntax.
Related benchmarks:
IndexOf vs Includes vs lodash includes
IndexOf vs Includes vs lodash includes test2
Array.indexOf vs Array.includes vs lodash includes with numerical values
IndexOf vs Includes vs _.includes for number array
Comments
Confirm delete:
Do you really want to delete benchmark?