Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array of objects equivalence (2)
(version: 0)
Comparing performance of:
custom vs lodash
Created:
5 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:
function equivalent(arr1, arr2) { if (arr1.length !== arr2.length) { return false } arr1.forEach((elem) => { const index = arr2.findIndex((elem2) => elem === elem2) if (index === -1) { // not found return false } arr2.splice(index, 1) // remove element }) if (arr2.length > 0) { // if still values in arr2, they are not in arr1 return false } return true } function _equiv(arr1, arr2) { return _.isEqual(_.sortBy(arr1), _.sortBy(arr2)) }
Tests:
custom
const arr1 = [{ KMFGNHeL: 0.2033444758693359, HJMzVLhZ: 373, WeKLrVwh: 'BlgvHn', hutdufbF: 'dfalRd', XqrwJjnR: null }, { xSUdtASV: 'ejVI', pgUHOMNn: true, dhQPzxuj: false, MHUchilq: 719, TWHkCOOT: 0.46691745627158165 }] const arr2 = [{ fZhKYyQT: 379, WtnguXmc: 64, VaodnYbC: 0.7490618732830732, hGhDbXmd: { pQnhfhKR: 0.029586390538915097, oSpBStGM: { dKoUrTyg: 0.8023980228055398, RMSlVEQw: null, KiPTRmIf: 'GIfgX', OOpGOzXD: null, YSTcLKDa: 777 }, eDsjVaPK: null, LrqwYwJs: 0.4117401997875565, AbIoXBix: 'THmFh' }, anQZVYxA: 0.8284963046084715 }] equivalence(arr1, arr2)
lodash
const arr1 = [{ KMFGNHeL: 0.2033444758693359, HJMzVLhZ: 373, WeKLrVwh: 'BlgvHn', hutdufbF: 'dfalRd', XqrwJjnR: null }, { xSUdtASV: 'ejVI', pgUHOMNn: true, dhQPzxuj: false, MHUchilq: 719, TWHkCOOT: 0.46691745627158165 }] const arr2 = [{ fZhKYyQT: 379, WtnguXmc: 64, VaodnYbC: 0.7490618732830732, hGhDbXmd: { pQnhfhKR: 0.029586390538915097, oSpBStGM: { dKoUrTyg: 0.8023980228055398, RMSlVEQw: null, KiPTRmIf: 'GIfgX', OOpGOzXD: null, YSTcLKDa: 777 }, eDsjVaPK: null, LrqwYwJs: 0.4117401997875565, AbIoXBix: 'THmFh' }, anQZVYxA: 0.8284963046084715 }] _equiv(arr1, arr2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
custom
lodash
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):
I'll break down the provided JSON data and explain what's being tested, compared options, pros and cons, and other considerations. **Benchmark Definition** The benchmark definition is represented by the `Script Preparation Code` and `Html Preparation Code`. In this case: * The script preparation code defines two functions: `equivalent(arr1, arr2)` and `_equiv(arr1, arr2)`. * The `_equiv(arr1, arr2)` function is wrapped around another library function, `_isEqual(_.sortBy(arr1), _.sortBy(arr2))`, which comes from the Lodash JavaScript library. * The purpose of these functions is to test whether two arrays (`arr1` and `arr2`) are equivalent. **Options Compared** The options being compared are: 1. **Manual implementation**: The `equivalent(arr1, arr2)` function, which implements a custom algorithm to compare the two arrays. 2. **Lodash library**: The `_equiv(arr1, arr2)` function, which uses the Lodash library's `_isEqual` function to compare the sorted arrays. **Pros and Cons** * **Manual implementation (equivalent)**: + Pros: Customizable, lightweight, and potentially faster since it doesn't depend on a third-party library. + Cons: Error-prone, less readable, and may not be as efficient as a well-optimized library function. * **Lodash library (_equiv)**: + Pros: Well-tested, optimized, and easy to read. + Cons: Additional dependency, potentially slower than a custom implementation. **Other Considerations** * The benchmark tests the performance of both options on identical data sets. * The use of Lodash's `_isEqual` function simplifies the comparison process but introduces an additional dependency. **Library Explanation (Lodash)** The Lodash library is a popular JavaScript utility library that provides a wide range of functions for various tasks, such as: * String manipulation * Array manipulation * Object manipulation * Functional programming helpers * And more! In this benchmark, the `_.isEqual` function from Lodash is used to compare two arrays. It returns a boolean value indicating whether the two arrays are equal. **Special JS Feature/Syntax** There doesn't appear to be any special JavaScript features or syntax being tested in this benchmark. **Alternative Approaches** Other alternatives for implementing array equivalence could include: * Using a different library, such as `lodash-es` (a more modern version of Lodash) or another library like `fast-json-stamp`. * Implementing a custom algorithm using a different approach, such as using a hash function to generate a unique fingerprint for each array. * Using a more specialized data structure, such as a trie or a suffix tree, to efficiently compare arrays. Keep in mind that these alternatives would likely have their own pros and cons, which would need to be evaluated on a case-by-case basis.
Related benchmarks:
Intersection filter vs lodash intersection test unsorted array
equiv arrays 3
Array equivalence
Array of objects equivalence (custom vs lodash)
Comments
Confirm delete:
Do you really want to delete benchmark?