Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash, Set, Array comparison v2
(version: 0)
Comparing performance of:
Lodash vs Array 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:
const rand = () => Math.floor(Math.random() * 1000) var arrays = Array(12).fill(null).map(()=>Array(81).fill(null)) arrays = arrays.map((b) => {return b.map(c => {return rand()})})
Tests:
Lodash
_.intersection(...arrays)
Array
arrays.reduce((a, b) => a.filter(c => b.includes(c)))
Set
new Set(...arrays)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Array
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 JSON benchmark definition and test cases. **Benchmark Overview** The benchmark measures the performance of three different data structures: Lodash, Set, and Array. The goal is to compare how efficiently each data structure can find common elements between two arrays. **Options Compared** The three options being compared are: 1. **Lodash**: A popular JavaScript utility library that provides a wide range of functions for manipulating arrays and objects. 2. **Set**: A built-in JavaScript data structure that stores unique values in a specific order. 3. **Array**: The native JavaScript array data structure, which can be used to store and manipulate collections of values. **Pros and Cons** * **Lodash**: Provides a simple and efficient way to find common elements between two arrays using the `_.intersection` function. However, it requires importing the Lodash library, which may add overhead. * **Set**: Offers a fast and memory-efficient way to store unique values in an array-like data structure. However, it requires creating a new Set object, which can be costly in terms of memory allocation. * **Array**: Provides a lightweight and flexible way to manipulate arrays, but requires manual implementation of the common element detection logic. **Library Used** The `lodash` library is used in the benchmark definition for the Lodash test case. It provides the `_.intersection` function, which takes two arrays as input and returns an array containing only the elements that are present in both input arrays. **Special JavaScript Feature or Syntax** There doesn't appear to be any special JavaScript features or syntax used in this benchmark. The code is relatively straightforward and uses standard JavaScript constructs. **Other Alternatives** If you want to implement a similar benchmark, here are some alternatives: * Use `filter()` method on the array to find common elements. * Create a custom function that iterates over one of the arrays and checks for presence in the other array using `includes()`. * Use a different library or framework that provides an efficient array intersection algorithm. **Benchmark Preparation Code Explanation** The script preparation code generates two arrays of random integers, each with 81 elements. The `fill()` method is used to initialize the arrays with null values, and then the `map()` method is used to generate random numbers for each element in the array. This creates a large dataset that can be used to benchmark the performance of each data structure. The HTML preparation code includes a script tag that loads the Lodash library from a CDN.
Related benchmarks:
Unique lodash vs vanilla
Lodash, Set, Array comparison
Lodash, Set, Array, Native comparison
lodash uniq vs Array.from(new Set()) vs spread new Set() [big arrays 2]
Comments
Confirm delete:
Do you really want to delete benchmark?