Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_isEqual vs. .every()
(version: 0)
Comparing performance of:
_.isEqual test vs .every()
Created:
3 years ago
by:
Registered User
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:
window.set1 = [ "456e7ee6-4385-48a5-ac9c-14425ab3a98a", "aefc0595-5809-41e1-838b-e8389dfd53d3", "abc25c34-ea76-47d4-8ce8-fb185638d785", "0dc13e1e-66ee-4620-a794-340eae89715a", "31613005-94af-46ba-8968-8b403565657b", "1117ceb0-bcd1-478b-a5f2-6fb3b241f57b", "74309762-0d19-4de8-aef9-657a0aae8b2b", "962538fc-cf3c-49bd-b409-e77b166e1517", "8c7b5e6a-48d6-4620-ba83-ea635bfe054d", "06c422cd-1923-41d4-9ef5-f9a95acce95f", "90ef0140-da61-41b3-9278-f6dc89b00f16", "744f1777-353c-4ead-a9f2-68150c5cf277", "36a4e93c-c8c4-41d1-a30e-6609f2016dd5", "2fd942af-83dc-4f77-818c-14305f65134c", "b94910f6-b3de-46b5-bd8e-36e261e1f7a9", "10964709-d92c-4f79-8147-230e984afd2e", "7eee0e6c-7b5e-4171-a7e4-1086cc4085a7", "6e7702e3-cdfb-4d5d-835e-20ab8920cba2", "58392634-9844-465c-8323-bdd2530f51f2", "17726b87-1a3a-489d-ac1f-0053bfef92bd", "0aa35748-08fd-444e-81d3-9d9b61f08b22", "66a91724-bb90-496f-a515-8e93802957e6" ] window.set2 = [ "456e7ee6-4385-48a5-ac9c-14425ab3a98a", "aefc0595-5809-41e1-838b-e8389dfd53d3", "abc25c34-ea76-47d4-8ce8-fb185638d785", "31613005-94af-46ba-8968-8b403565657b", "17726b87-1a3a-489d-ac1f-0053bfef92bd", "1117ceb0-bcd1-478b-a5f2-6fb3b241f57b", "74309762-0d19-4de8-aef9-657a0aae8b2b", "962538fc-cf3c-49bd-b409-e77b166e1517", "8c7b5e6a-48d6-4620-ba83-ea635bfe054d", "06c422cd-1923-41d4-9ef5-f9a95acce95f", "90ef0140-da61-41b3-9278-f6dc89b00f16", "744f1777-353c-4ead-a9f2-68150c5cf277", "36a4e93c-c8c4-41d1-a30e-6609f2016dd5", "2fd942af-83dc-4f77-818c-14305f65134c", "b94910f6-b3de-46b5-bd8e-36e261e1f7a9", "10964709-d92c-4f79-8147-230e984afd2e", "7eee0e6c-7b5e-4171-a7e4-1086cc4085a7", "0dc13e1e-66ee-4620-a794-340eae89715a", "6e7702e3-cdfb-4d5d-835e-20ab8920cba2", "58392634-9844-465c-8323-bdd2530f51f2", "0aa35748-08fd-444e-81d3-9d9b61f08b22", "66a91724-bb90-496f-a515-8e93802957e6" ]
Tests:
_.isEqual test
_.isEqual(window.set1, window.set2)
.every()
window.set1.every(id => window.set2.indexOf(id) >= 0);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.isEqual test
.every()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0
Browser/OS:
Chrome 124 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.isEqual test
2364852.0 Ops/sec
.every()
388414.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **Benchmark Definition** The benchmark definition is provided in JSON format and defines two test cases: 1. `_.isEqual(window.set1, window.set2)`: This test case uses the Lodash library to compare two arrays (`window.set1` and `window.set2`) for equality. 2. `window.set1.every(id => window.set2.indexOf(id) >= 0)`: This test case uses a custom every() function to check if all elements in `window.set1` are present in `window.set2`. **Options Compared** The two options being compared are: * Using the built-in `Array.prototype.includes()` method (in the second test case) * Using the Lodash library's `_.isEqual()` function (in the first test case) These two approaches differ in their implementation and potential performance implications. **Pros and Cons of Each Approach** 1. **Built-in `Array.prototype.includes()` method**: This is a simple, lightweight approach that uses a linear search to find an element in the array. * Pros: + Fast and efficient + Lightweight (no external dependencies) * Cons: + May be slower for large arrays due to the linear search 2. **Lodash library's `_.isEqual()` function**: This is a more complex approach that uses a custom algorithm to compare arrays. * Pros: + Can handle large arrays efficiently using a optimized algorithm + Provides additional features, such as handling nested objects * Cons: + Requires an external dependency (the Lodash library) + May be slower due to the added complexity **Individual Test Cases** The two individual test cases are: 1. `_.isEqual(window.set1, window.set2)`: This test case uses the Lodash library's `_.isEqual()` function to compare the two arrays. 2. `window.set1.every(id => window.set2.indexOf(id) >= 0)`: This test case uses a custom every() function to check if all elements in `window.set1` are present in `window.set2`. **Latest Benchmark Result** The latest benchmark result shows that: * The built-in `Array.prototype.includes()` method performs slightly better than the Lodash library's `_.isEqual()` function (with 388,414.59375 executions per second vs 236,485.2 executions per second). * However, it's worth noting that these results may vary depending on the specific hardware and browser used. **Conclusion** In conclusion, this benchmark compares two approaches to checking array equality: using the built-in `Array.prototype.includes()` method versus the Lodash library's `_.isEqual()` function. While both approaches have their pros and cons, the built-in approach appears to be slightly faster in this particular test case. However, it's essential to consider factors such as performance, readability, and maintainability when choosing an approach for your specific use case.
Related benchmarks:
Lodash vs. Set Intersection reverse2
Set union
IndexOf vs Includes vs lodash includes LARGE
Lodash.isEqual vs ES6 Sets Equality Comparison for Shallow Array of numbers.
Comments
Confirm delete:
Do you really want to delete benchmark?