Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
IndexOf vs Includes vs lodash includes
(version: 0)
Banana
Comparing performance of:
IndexOf vs Includes vs lodash
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 array = ['banana', 'sausage', 'jesus']
Tests:
IndexOf
array.indexOf('sausage') !== 1
Includes
array.includes('sausage')
lodash
_.includes(array, 'sausage')
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:
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
IndexOf
21744048.0 Ops/sec
Includes
19966758.0 Ops/sec
lodash
6236047.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark named "IndexOf vs Includes vs lodash includes". This benchmark tests the performance of three different approaches for searching an element in an array: `indexOf`, `includes`, and a custom implementation using the popular library Lodash (`_.includes`). **Script Preparation Code** The script preparation code is: ```javascript var array = ['banana', 'sausage', 'jesus']; ``` This creates an array of three elements, which will be used as the input for the benchmark. **Html Preparation Code** The HTML preparation code includes a reference to the Lodash library version 4.17.5: ``` <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> ``` This allows the benchmark to use the `_.includes` function from Lodash. **Test Cases** There are three test cases in total: 1. **IndexOf**: This test case uses the built-in `indexOf` method of the array. ```javascript array.indexOf('sausage') !== 1 ``` The `indexOf` method searches for the specified element in the array and returns its index. If the element is not found, it returns -1. **Pros and Cons of Using Built-in Methods** * Pros: + Fast and efficient + Widely supported by most browsers * Cons: + May not be as performant as custom implementations for very large arrays 2. **Includes**: This test case uses the built-in `includes` method of the array. ```javascript array.includes('sausage') ``` The `includes` method checks if the specified element is present in the array and returns a boolean value indicating whether it's found. **Pros and Cons of Using Built-in Methods** * Pros: + Fast and efficient + Widely supported by most browsers * Cons: + May not be as performant as custom implementations for very large arrays 3. **Lodash includes**: This test case uses the `_.includes` function from Lodash. ```javascript _.includes(array, 'sausage') ``` The `_.includes` function checks if the specified element is present in the array and returns a boolean value indicating whether it's found. **Pros and Cons of Using Lodash** * Pros: + Fast and efficient + Customizable and extensible + Wide range of features beyond just includes() * Cons: + Requires including an external library (Lodash) + May not be as performant as built-in methods in some cases **Device Platform and Browser Information** The latest benchmark result shows that the test was executed on a Mac OS X 10.15.7 device with Chrome 127 browser, running at 25065294 executions per second for the "Includes" test case. **Other Alternatives** If you wanted to use alternative approaches to search for elements in an array, some other options might include: * Using a custom implementation using bitwise operations or regular expressions * Using a library like Fast.js or Ramda instead of Lodash * Using a different data structure like a Set or Map However, it's worth noting that the built-in `indexOf` and `includes` methods are generally the most efficient and widely supported options for this use case.
Related benchmarks:
IndexOf vs Includes -- Strings
IndexOf vs Includes vs lodash includes test2
IndexOf vs Includes vs lodash includes for string
array IndexOf vs array Includes vs lodash indexOf
Comments
Confirm delete:
Do you really want to delete benchmark?