Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.isEqual vs ES6 Sets Equality Comparison for Shallow Array of numbers.
(version: 0)
Test on isEqual performance
Comparing performance of:
_.isEqual vs Sets
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
window.foo = [14003340, 14003491, 14003492, 14003493, 14003494, 14003495, 14003496, 14003497, 14003498, 14003499, 14003500, 14003501, 14003502, 14003503, 14003504, 14003505, 14003506, 14003507, 14003508, 14003509, 14003510, 14003511, 14003512, 14003513, 14003514, 14003515, 14003516, 14003517, 14003518, 14003519, 14003520, 14003521, 14003522, 14003523, 14003524, 14003525, 14003531, 14003547, 14003548 ]; window.bar = [14003548, 14003515, 14003547, 14003518, 14003517, 14003521, 14003520, 14003519, 14003522, 14003523, 14003524, 14003525, 14003340, 14003492, 14003491, 14003514, 14003513, 14003511, 14003512, 14003509, 14003508, 14003507, 14003494, 14003493, 14003495, 14003496, 14003497, 14003498, 14003499, 14003501, 14003500, 14003502, 14003503, 14003504, 14003531, 14003506, 14003505, 14003516, 14003510 ];
Tests:
_.isEqual
_.isEqual(window.foo, window.bar)
Sets
const equals = (setA, setB) => !!( setA && setB && setA.size === setB.size && Array.from(setA).every((a) => setB.has(a)) ); equals(new Set(window.foo), new Set(window.bar));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.isEqual
Sets
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser/OS:
Chrome 144 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.isEqual
13190460.0 Ops/sec
Sets
822149.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! The provided JSON represents a benchmark test case for measuring the performance of two approaches: Lodash's `isEqual` function and ES6 Sets equality comparison. **Benchmark Definition** The benchmark definition is divided into two parts: 1. **Script Preparation Code**: This code defines two arrays, `window.foo` and `window.bar`, which will be used as input for the benchmark tests. 2. **Html Preparation Code**: This line includes a script tag that loads the Lodash library (version 4.17.4) from a CDN. **Individual Test Cases** There are two test cases: 1. **Lodash.isEqual** The first test case measures the performance of Lodash's `isEqual` function when comparing `window.foo` and `window.bar`. 2. **Sets** The second test case uses an alternative approach, implementing a custom equality comparison function using ES6 Sets. **What is tested?** In both test cases, the benchmark measures the time it takes to determine whether two arrays are equal. The main differences between the two approaches are: * **Lodash.isEqual**: Uses Lodash's implementation of `isEqual`, which likely involves a more complex algorithm for comparing array elements. * **Sets**: Uses ES6 Sets to compare array elements. This approach is simpler and more efficient, as it leverages the built-in Set data structure in JavaScript. **Options compared** The two test cases compare the performance of: 1. **Lodash.isEqual** 2. **ES6 Sets equality comparison** **Pros and Cons:** * **Lodash.isEqual**: + Pros: - Well-tested and widely used implementation - May be more robust for complex array comparisons + Cons: - Smaller performance overhead compared to ES6 Sets * **ES6 Sets equality comparison**: + Pros: - Highly efficient, as it leverages the built-in Set data structure - Simplified implementation + Cons: - May not be as robust for complex array comparisons **Other considerations:** * The benchmark uses a Desktop Windows 10 system, which may have an impact on performance due to factors like registry access and memory management. * Chrome 106 is used as the browser, but other browsers may yield different results. **Alternatives:** For similar benchmarks, you might also consider: 1. **JSON.stringify()**: This approach involves converting arrays to strings using `JSON.stringify()` and comparing the resulting strings. 2. **Array.prototype.every()**: This method iterates over an array and returns a boolean indicating whether all elements pass a provided test function. These alternatives may provide different performance characteristics, depending on the specific use case and implementation details.
Related benchmarks:
Lodash.isEqual vs Array.toString() Equality Comparison for Shallow Array of Strings.
Lodash.isEqual vs Array.join() Equality Comparison for Shallow Array of integers.
Lodash.isEqual vs Lodash.isEqualWith Equality Comparison for Shallow Array of Strings.
Lodash isEqual test (slightly bigger test data)
Comments
Confirm delete:
Do you really want to delete benchmark?