Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.get(with new set) vs native include vs lodash include
(version: 0)
Comparing performance of:
lodash includes vs native includes vs set. has
Created:
one year 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 arr = [] for(var i = 0; i < 999999; i++) { arr.push(Math.random()) }
Tests:
lodash includes
_.includes(arr, Math.random())
native includes
arr.includes(Math.random())
set. has
var demoSet = new Set(arr);demoSet.has(Math.random())
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash includes
native includes
set. has
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash includes
1059.0 Ops/sec
native includes
6785.0 Ops/sec
set. has
12.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark, hosted on MeasureThat.net, compares the performance of three different approaches to check if an element exists in an array: native includes, Lodash's `includes` function, and the `has` method of JavaScript's built-in `Set` data structure. **Approaches Compared** 1. **Native Includes**: This approach uses the native `includes` method on the array, which checks for membership in a sequence. 2. **Lodash Includes**: This approach uses Lodash's `includes` function, which is a utility function that checks if an element exists in an array. 3. **Set.has**: This approach creates a new `Set` instance from the array and then uses the `has` method to check for membership. **Pros and Cons of Each Approach** 1. **Native Includes** * Pros: + Fastest and most efficient approach (no additional function call overhead). + Built-in method, so no additional library dependency. * Cons: + May not be as readable or maintainable as other approaches (e.g., `includes` method can make the code harder to understand). 2. **Lodash Includes** * Pros: + More readable and maintainable than native includes (clearly conveys intent of checking for membership in an array). + Provides a standardized way of doing array checks across different JavaScript environments. * Cons: + Slower than native includes due to the function call overhead. + Requires additional library dependency (Lodash). 3. **Set.has** * Pros: + Most readable and maintainable approach (clearly conveys intent of checking for membership in a set). + Can be more efficient than native includes if the array is very large, since it uses a data structure that can take advantage of caching. * Cons: + Requires creating a new `Set` instance from the array, which may incur additional overhead (e.g., memory allocation, garbage collection). **Other Considerations** * The benchmark creates a large array with random elements to simulate real-world scenarios and minimize the impact of small variations in array sizes. * The Lodash library is included via a CDN link to ensure that the test runs consistently across different environments. **Library and Syntax Used** * **Lodash**: A popular JavaScript utility library that provides a wide range of functions for working with arrays, objects, and other data structures. In this benchmark, Lodash's `includes` function is used to check if an element exists in an array. * No special JavaScript features or syntax are used beyond the standard language. **Alternatives** If you're looking for alternative approaches to checking for membership in an array, consider: 1. **Array.prototype.indexOf()**: This method returns the index of the first occurrence of a specified value, or -1 if the value is not found. 2. **Array.prototype.includes()** (ES6+): This method checks if a value exists in an array and returns a boolean indicating whether it does or not. 3. **custom implementation**: You can also implement your own custom function to check for membership in an array, which may provide better performance or customization options depending on your specific use case.
Related benchmarks:
Unique lodash vs vanilla
set.get(with new set) vs native include vs lodash include in small data scale
set.get vs native include vs lodash include in small data scale
set.get (not new set) vs native include vs lodash include in small data scale
Comments
Confirm delete:
Do you really want to delete benchmark?