Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
includes() vs _.includes
(version: 1)
Comparing performance of:
Native vs Lodash
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
Script Preparation code:
var arr = [ [{n: 1}, {n: 2}, {n: 3}, {n: 4}, {n: 5}], [{n: 1}, {n: 3}, {n: 5}], [{n: 1}, {n: 5}] ]; var targets = [1, 5];
Tests:
Native
arr.forEach(el => targets.includes(el));
Lodash
_.forEach(arr, function(value){ value => _.includes(targets, value.n, 0) });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
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.1:latest
, generated one year ago):
Let's dive into the details of this benchmark. **What is being tested?** The benchmark compares two approaches to check if an element exists in an array: 1. Using the built-in `includes()` method (Native) 2. Using the `_includes` function from the Lodash library (Lodash) **Description of options compared:** * **Native**: This approach uses the built-in `includes()` method, which is a part of the JavaScript language. It takes two arguments: the array to search in (`arr`) and the value to search for (`targets`). The method returns a boolean indicating whether the value exists in the array or not. * **Lodash**: This approach uses the `_includes` function from the Lodash library, which is a utility library that provides various functions for common tasks. In this case, the `_includes` function takes three arguments: the array to search in (`arr`), the value to search for (`value.n`, where `value` is an element of the array and `n` is a property of that element), and an optional index from which to start searching (in this case, 0). **Pros/Cons of different approaches:** * **Native**: The built-in `includes()` method is generally faster than using a library function. However, it may not be as robust or feature-rich as a dedicated library function. + Pros: Faster execution time, native to JavaScript language + Cons: May not have additional features or edge cases handled * **Lodash**: The `_includes` function from Lodash is more robust and can handle various edge cases that the built-in `includes()` method may not. However, it requires loading an external library. + Pros: More robust and feature-rich, handles edge cases + Cons: Requires loading an external library, may be slower than native implementation **Other considerations:** * **Library usage**: The test case uses Lodash, which is a popular utility library for JavaScript. If you're already using Lodash in your project, it might make sense to use its `_includes` function. * **Special JS feature or syntax**: This benchmark does not use any special JavaScript features or syntax beyond what's already available in the language. **Alternatives:** If you need a more robust or feature-rich implementation of array inclusion checks, you could consider using other libraries like Underscore.js or a custom implementation. However, if performance is your primary concern, sticking with the native `includes()` method might be the best choice. I hope this explanation helps!
Related benchmarks:
arr test
Lodash some vs includes
Array.indexOf vs Array.includes vs lodash includes with numerical values
JavaScript Benchmark: includes vs indexOf
array using indexOf vs includes vs some
Comments
Confirm delete:
Do you really want to delete benchmark?