Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash, Set, Array, Native comparison
(version: 0)
Comparing performance of:
Lodash vs Array vs Set vs Native
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)
Native
arrays.reduce(function(a, b) { return a.filter(function(value) { return b.includes(value); }); })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash
Array
Set
Native
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 and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark is designed to compare the performance of three approaches: 1. Lodash (a JavaScript library) 2. Array.prototype.filter() (native JavaScript method) 3. Set data structure ( native JavaScript data type) The goal is to find out which approach is most efficient for finding common elements between two arrays. **Script Preparation Code** This code generates a large array of 12 sub-arrays, each containing 81 random numbers. This is done using the `Array` constructor and `map()` method. ```javascript 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()})}) ``` **Html Preparation Code** This code includes a reference to the Lodash library, which is used in one of the benchmark definitions. ```javascript <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> ``` **Individual Test Cases** The benchmark consists of four test cases: 1. **Lodash: _.intersection(...)** * Uses Lodash's `_.intersection()` method to find common elements between two arrays. * Pros: Easy to read and maintain, well-documented library. * Cons: Adds an extra dependency (the Lodash library), may incur a slight overhead due to the library's size. 2. **Array: reduce()** * Uses Array.prototype.filter() in combination with reduce() to find common elements between two arrays. * Pros: Native JavaScript method, no additional dependencies required. * Cons: May be less efficient than Lodash's optimized implementation, more complex code. 3. **Set: new Set()** * Uses the Set data structure to find common elements between two arrays. * Pros: Efficient and native JavaScript data type, no additional dependencies required. * Cons: May require more memory due to the set's overhead, less intuitive code for some developers. 4. **Native (Array.prototype.filter()):** * Repeats the Array prototype filter() method implementation in the test case. **Benchmark Results** The benchmark results show the performance of each approach on a specific device: | Test Name | Browser | DevicePlatform | OperatingSystem | ExecutionsPerSecond | | --- | --- | --- | --- | --- | | Native | Chrome 116 | Desktop | Mac OS X 10.15.7 | 848299.0625 | | Array | Chrome 116 | Desktop | Mac OS X 10.15.7 | 843935.8125 | | Set | Chrome 116 | Desktop | Mac OS X 10.15.7 | 686331.4375 | | Lodash | Chrome 116 | Desktop | Mac OS X 10.15.7 | 130510.9453125 | **Other Alternatives** If the developers want to explore other approaches, they could consider: * Using a different library or implementation for finding common elements (e.g., using a custom array algorithm). * Investigating other native JavaScript methods or data structures (e.g., using Array.prototype.find() and filter() together). * Optimizing the Lodash implementation specifically for this use case. Keep in mind that these alternatives would require significant changes to the existing benchmark code and may not provide a clear understanding of the performance trade-offs involved.
Related benchmarks:
Unique lodash vs vanilla
Lodash, Set, Array comparison
Lodash, Set, Array comparison v2
lodash uniq vs Array.from(new Set()) vs spread new Set() [big arrays 2]
Comments
Confirm delete:
Do you really want to delete benchmark?