Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
IndexOf vs Includes vs lodash includes vs Set
(version: 0)
Banana
Comparing performance of:
IndexOf vs Includes vs lodash vs Set
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', 'ENTITY', 'THING', 'SOLID_THING', 'FLUIDO', 'PIEZA', 'PIEZA_ELECTRICA', 'PIEZA_MECANICA', 'CODIGO', 'SISTEMA', 'INDICADOR_DE_ERROR', 'PROP', 'FUNCIONALIDAD']; var s = new Set(array);
Tests:
IndexOf
array.indexOf('sausage') !== 1
Includes
array.includes('sausage')
lodash
_.includes(array, 'sausage')
Set
s.has('sausage')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
IndexOf
Includes
lodash
Set
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
22072408.0 Ops/sec
Includes
21155258.0 Ops/sec
lodash
6265599.5 Ops/sec
Set
34640772.0 Ops/sec
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 is designed to compare the performance of four different approaches: 1. `indexOf` (native JavaScript method) 2. `includes` (native JavaScript method, introduced in ECMAScript 2019) 3. `_` (lodash library function `_.includes`) 4. `Set` (using a `Set` data structure) **What's being tested** For each test case, the benchmark measures how many executions per second are possible for each approach on the provided input array (`array`). The execution time is reported in seconds. **Approaches and their pros/cons** 1. **Native JavaScript `indexOf` and `includes` methods** * Pros: Native code, no external dependencies. * Cons: May have varying performance depending on browser and engine implementation. 2. **Lodash library function `_`** * Pros: Well-tested and widely used library with optimized implementations. * Cons: External dependency, which may introduce overhead in some scenarios. 3. **Set data structure** * Pros: Efficient for membership testing, especially for large datasets. * Cons: May require additional memory allocation and garbage collection. **Test Case Breakdown** For each test case: 1. `IndexOf` * Native JavaScript method is used to find the index of a substring in the array using `array.indexOf('sausage')`. * The benchmark measures how many times this operation can be executed per second. 2. `Includes` * Similar to `IndexOf`, but uses the native JavaScript method with the new `includes` keyword: `array.includes('sausage')`. 3. `_ (Lodash) Includes` * Lodash's `_.includes` function is used to find if a value exists in an array, which in this case is just checking for membership. 4. `Set` * A `Set` data structure is created from the input array, and then its `has` method is used to check if a specific element exists within it. **Special JS feature/syntax** There's no special JavaScript feature or syntax explicitly being tested in this benchmark. However, the use of the `_includes` method (from lodash) may be an interesting consideration for those familiar with functional programming and higher-order functions. **Alternatives** For further comparison, other approaches could be: 1. Using a custom implementation of `indexOf` and `includes`, which would allow developers to fine-tune performance optimizations. 2. Utilizing other libraries or frameworks that provide optimized implementations for membership testing (e.g., `Fast-String-Matches`). 3. Investigating the use of alternative data structures, such as `Map` instead of `Set`. 4. Using different programming paradigms, like functional programming with `filter()` and `some()` methods. Keep in mind that these alternatives might introduce additional dependencies or complexity, which could impact performance and scalability.
Related benchmarks:
IndexOf vs Includes vs lodash includes
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?