Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array IndexOf vs array Includes vs lodash indexOf
(version: 0)
Banana
Comparing performance of:
IndexOf vs Includes vs lodash
Created:
5 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
_.indexOf(array, 'sausage') !== 1
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 provided JSON and benchmarking code to understand what is being tested. **Overview** The `MeasureThat.net` website allows users to create and run JavaScript microbenchmarks. The provided benchmark compares three approaches for searching an array of strings: `indexOf`, `includes`, and a custom implementation using the `lodash` library. **Script Preparation Code** The script preparation code creates an array `array` with three elements: `'banana'`, `'sausage'`, and `'jesus'`. ```javascript var array = ['banana', 'sausage', 'jesus']; ``` **Html Preparation Code** The HTML preparation code includes a reference to the `lodash.js` library, which is used in one of the test cases. ```html <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> ``` **Individual Test Cases** There are three test cases: 1. **IndexOf**: Tests if `indexOf('sausage')` returns 1. 2. **Includes**: Tests if `includes('sausage')` returns a boolean value (true or false). 3. **lodash**: Tests if `_.indexOf(array, 'sausage') !== 1` using the `lodash` library. **What is tested** The benchmark tests the performance of each approach: * `indexOf`: The native JavaScript method for finding the index of an element in an array. * `includes`: A built-in JavaScript method that checks if an array contains a specified value. * `_`.indexOf: A method from the `lodash` library that performs the same operation as `indexOf`. **Options compared** The benchmark compares two approaches: 1. Native JavaScript methods (`indexOf` and `includes`) 2. The `lodash` library's `_.indexOf` method **Pros and Cons of each approach** * **Native JavaScript methods (indexOf, includes)**: * Pros: Built-in functions with minimal overhead. * Cons: May not be as efficient for large arrays or specific use cases, as they can create unnecessary iterations. * **_lodash_.indexOf**: * Pros: Customizable, potentially more efficient than native methods in some scenarios. Can provide additional features like handling null/undefined values and custom search functions. * Cons: Introduces an extra dependency (the `lodash` library) and may have a slight performance overhead due to the added function call. **Special considerations** * The benchmark does not explicitly use any special JavaScript features or syntax, as it focuses on the core functionality of each approach. * It's essential to note that the actual performance differences between these methods can be affected by various factors like array size, iteration complexity, and platform-specific optimizations.
Related benchmarks:
IndexOf vs Includes vs lodash includes
IndexOf vs Includes vs lodash includes test2
IndexOf vs Includes vs lodash includes for string
IndexOf vs Includes vs lodash includes2
Comments
Confirm delete:
Do you really want to delete benchmark?