Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
IndexOf vs Includes vs lodash includes vs Setasdf
(version: 0)
Banana
Comparing performance of:
IndexOf vs Includes vs lodash vs Set
Created:
3 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('INDICADOR_DE_ERROR') !== 1
Includes
array.includes('INDICADOR_DE_ERROR')
lodash
_.includes(array, 'INDICADOR_DE_ERROR')
Set
s.has('INDICADOR_DE_ERROR')
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:
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 definition and test cases to understand what is being tested. **Benchmark Definition:** The benchmark is designed to compare the performance of different string search methods: * `indexOf`: a built-in JavaScript method that searches for a specific value in an array or string. * `includes`: another built-in JavaScript method that checks if a string contains a specific value. * `_.includes` (from the Lodash library): a utility function from the Lodash library that performs the same check as `includes`. * `Set`: using a Set data structure to store unique values and then checking for presence. **Library:** The Lodash library is being used in this benchmark. Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like string manipulation, array operations, and more. **String Search Methods:** * `indexOf`: + Pros: Simple, efficient, and widely supported. + Cons: May not be as performant for large datasets or complex search patterns. * `includes`: + Pros: More flexible than `indexOf`, can handle regular expressions, and is more performant for large datasets. + Cons: May have performance overhead due to the use of a regex engine. * `_.includes` (Lodash): + Pros: Provides an optimized implementation with better performance than the built-in `includes`. + Cons: Requires including the Lodash library, which may add additional overhead. * `Set`: + Pros: Fast and efficient for checking presence in a large dataset. + Cons: May have higher memory usage due to storing all unique values. **Considerations:** * The benchmark is designed to test the performance of each string search method across different scenarios, including searching for a single value (`IndexOf`) versus searching for multiple values (`Includes`). * The use of a Set data structure in the `Set` test case highlights its efficiency in checking presence. * The inclusion of Lodash's `_.includes` function provides an alternative implementation that may offer better performance. **Alternative String Search Methods:** * Other methods not tested here include: + `String.prototype.indexOf()` (similar to `indexOf`, but without the `array` context) + Regular expressions (`RegExp.test()`) + Custom implementations using iteration or other optimization techniques In summary, this benchmark compares the performance of different string search methods in JavaScript, including built-in methods like `indexOf` and `includes`, as well as a library-based implementation with Lodash. The results highlight the efficiency of using a Set data structure for checking presence and the potential benefits of using an optimized implementation like Lodash's `_.includes`.
Related benchmarks:
IndexOf vs Includes vs lodash includes
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?