Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
IndexOf vs Includes vs lodash includes numbers
(version: 0)
Banana
Comparing performance of:
IndexOf vs Includes vs lodash
Created:
4 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.5/lodash.min.js'></script>
Script Preparation code:
var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
Tests:
IndexOf
array.indexOf(9)
Includes
array.includes(9)
lodash
_.includes(array, 9)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
IndexOf
Includes
lodash
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 benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares three different approaches to check if an element exists in an array: 1. `Array.indexOf()` 2. `Array.includes()` 3. `_` (using Lodash) **Options Compared** The options are compared in terms of their execution speed, measured in executions per second. * `indexOf()` and `includes()` are built-in methods in JavaScript arrays. * `_` is a function from the Lodash library, which provides a more comprehensive set of utility functions. **Pros and Cons of Each Approach** 1. **Array.indexOf()**: * Pros: Fast, lightweight, and widely supported. * Cons: May not be as readable or expressive as other approaches, as it returns -1 for non-existent elements. 2. **Array.includes()**: * Pros: More readable than `indexOf()` in terms of intention (it explicitly states "does this element exist?"). * Cons: May have slightly worse performance compared to `indexOf()`. 3. **Lodash's `_` function**: * Pros: Provides a more comprehensive set of utility functions, making it a good choice for complex operations. * Cons: Adds an extra dependency (the Lodash library) and may be overkill for simple array checks. **Library Description** The Lodash library is a popular JavaScript utility library that provides a wide range of functions for tasks like: * Array manipulation * String manipulation * Object manipulation * Functional programming helpers In this benchmark, the `_includes()` function from Lodash is used to check if an element exists in an array. **Special JS Feature or Syntax** There is no special JavaScript feature or syntax being tested in this benchmark. The focus is on comparing the performance of different approaches to a simple problem (checking for the existence of an element in an array). **Other Alternatives** If you're looking for alternative approaches to checking if an element exists in an array, some other options might include: * Using `Array.prototype.every()` or `Array.prototype.some()`, which can be slower than `indexOf()` or `includes()`. * Implementing your own custom search function using a loop. * Using a more functional programming approach with methods like `findIndex()` or `some()`. Keep in mind that the choice of approach will depend on the specific requirements and performance constraints of your project.
Related benchmarks:
IndexOf vs Includes vs lodash includes 1231
Array IndexOf vs includes
indexOf VS includes in JavaScript Array
IndexOf vs Includes vs lodash includes2
Comments
Confirm delete:
Do you really want to delete benchmark?