Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.includes vs includes() vs indexof
(version: 0)
Comparing performance of:
Lodash vs Native vs native indexof
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', 'a', 'b', 'c', 'd', 'e', 'f', 'g', '1', '2','3'];
Tests:
Lodash
_.includes(data, 'f');
Native
data.includes('f');
native indexof
data.indexOf('f') > -1
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Native
native indexof
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 its test cases. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmark comparing three different approaches for checking if a value exists in an array: 1. `_.includes()` from the Lodash library 2. The native JavaScript method `includes()` 3. The native JavaScript method `indexOf()` with a check for `-1` to indicate presence **Options Being Compared** The test cases are comparing the performance of three different approaches: * `_.includes(data, 'f')`: This is using the Lodash library's `_.includes()` function. * `data.includes('f')`: This is the native JavaScript method for checking if a value exists in an array. * `data.indexOf('f') > -1`: This is the native JavaScript method for finding the index of a value in an array, with a check to indicate presence. **Pros and Cons of Each Approach** Here's a brief overview of each approach: * **Lodash's `_includes()`**: Pros: Convenient, easy to use, and often used in production code. Cons: It requires including an additional library, which may impact performance or bundle size. * **Native JavaScript `includes()`**: Pros: Lightweight, fast, and part of the standard library. Cons: May not be as convenient to use as Lodash's version. * **Native JavaScript `indexOf()` with `-1` check**: Pros: Very lightweight and fast, but requires two function calls (indexing followed by a comparison). Cons: Less readable and may be less intuitive for some developers. **Library Used** The test case uses the Lodash library. Lodash is a popular utility library that provides a lot of functional programming helpers, including `_.includes()`. The purpose of this library is to provide a convenient and reusable way to perform common tasks in JavaScript, such as array manipulation and function composition. **Special JS Feature or Syntax** None of the provided test cases use any special JavaScript features or syntax. They only rely on standard JavaScript language constructs. **Alternatives** Some alternatives for checking if a value exists in an array include: * Using `Array.prototype.some()` or `Array.prototype.every()`, which are also part of the standard library. * Implementing your own custom function for this task, which could be optimized for specific use cases. Overall, the provided benchmark is a useful comparison between three different approaches to checking if a value exists in an array. It highlights the trade-offs between convenience, performance, and readability in JavaScript development.
Related benchmarks:
_.includes vs includes()
IndexOf vs Includes vs lodash includes test2
IndexOf vs Includes vs lodash includes for string
_.includes vs includes() 2
Comments
Confirm delete:
Do you really want to delete benchmark?