Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.get vs native include vs lodash include in small data scale
(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 < 99; 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
4795727.0 Ops/sec
native includes
9846598.0 Ops/sec
set. has
495847.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is tested, compared, and other considerations. **Benchmark Overview** The benchmark measures the performance of three different approaches to check if an element exists in an array: 1. Using the `includes()` method (native JavaScript) 2. Using the `_includes()` function from the Lodash library 3. Using a Set data structure **Comparison of Approaches** 1. **Native includes**: This approach uses the built-in `includes()` method to check if an element exists in the array. * Pros: Fast and efficient, widely supported, and easy to implement. * Cons: May not perform well for large datasets or arrays with a high number of duplicate elements. 2. **Lodash includes**: This approach uses the `_includes()` function from the Lodash library, which is a popular utility library for JavaScript. * Pros: More robust and feature-rich than native `includes()`, can handle edge cases, and often provides better performance for certain use cases. * Cons: Requires additional dependency (Lodash), may introduce overhead due to library initialization, and might not be as fast as native implementation. 3. **Set.has**: This approach uses a Set data structure to store the array elements and then checks if an element exists using the `has()` method. * Pros: Can provide good performance for large datasets, handles duplicates well, and is often more memory-efficient than other approaches. * Cons: May require additional memory allocation for the Set data structure, can be slower due to the extra overhead of creating and managing the Set. **Library Overview** In this benchmark, Lodash is used as a utility library. Lodash provides a wide range of functional programming helpers, including `_includes()`, which is used in one of the test cases. **Special JS Feature/Syntax** There is no special JavaScript feature or syntax used in this benchmark. **Other Alternatives** If you're looking for alternative approaches to check if an element exists in an array, you might consider: * Using a different data structure, such as a Map or an Object with array values. * Implementing your own custom algorithm using bitwise operations or other optimization techniques. * Utilizing browser-specific features, like WebAssembly or SIMD instructions, which can provide performance optimizations for certain use cases. Keep in mind that the choice of approach depends on the specific requirements and constraints of your project.
Related benchmarks:
Unique lodash vs vanilla
set.get(with new set) vs native include vs lodash include
set.get(with new set) 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?