Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.get(with new set) 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
4778938.0 Ops/sec
native includes
9805094.0 Ops/sec
set. has
516067.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Overview** The benchmark measures the performance of three different approaches to check if an element exists in an array: 1. Lodash `_.includes()` 2. Native JavaScript `arr.includes()` method 3. Custom implementation using a `Set` object (`var demoSet = new Set(arr); demoSet.has(Math.random())`) **Options Compared** The benchmark compares the performance of each approach with the following options: * Use of Lodash library * Use of native JavaScript `includes()` method * Use of a custom implementation using a `Set` object **Pros and Cons of Each Approach** 1. **Lodash `_.includes()`** * Pros: + Provides a reliable and efficient way to check if an element exists in an array. + Allows for optional second argument to specify the value to search for (e.g., `_.includes(arr, Math.random())`). * Cons: + Introduces additional overhead due to the use of a library. 2. **Native JavaScript `arr.includes()` method** * Pros: + Fast and efficient implementation that is optimized for performance. + Does not introduce additional overhead beyond the native array operations. * Cons: + May not be as reliable or robust as Lodash's implementation, especially in edge cases. 3. **Custom implementation using a `Set` object** * Pros: + Can provide better performance than the native JavaScript implementation for large datasets. + Allows for fine-grained control over the iteration process. * Cons: + Requires manual management of the set and its operations, which can add complexity. **Library: Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functional programming helpers, including array methods like `_.includes()`. The `_.includes()` method is designed to be efficient and reliable, while also allowing for optional arguments to customize the behavior. In this benchmark, Lodash is used as-is, without any modifications or optimizations. **Other Considerations** * The test uses a small dataset with 99 random elements, which may not accurately represent real-world scenarios where datasets can be much larger. * The benchmark only measures the performance of each approach on the `includes()` method, but other methods like `indexOf()` or `findIndex()` may have different performance characteristics. **Alternatives** Other alternatives to Lodash's `_.includes()` method include: * Using a simple loop-based implementation: `for (var i = 0; i < arr.length; i++) { if (arr[i] === Math.random()) { /* found */ } }` * Utilizing other array methods like `some()`, `every()`, or `find()`, which may have different performance characteristics. Keep in mind that the choice of implementation ultimately depends on the specific use case, performance requirements, and personal preference.
Related benchmarks:
Unique lodash vs vanilla
set.get(with new set) vs native include vs lodash include
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?