Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.isEqual vs dequal 2
(version: 0)
Comparing performance of:
lodash.isEqual vs dequal
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script> <script src="https://unpkg.com/dequal@2.0.2/dist/index.min.js"></script>
Script Preparation code:
function equal(a, b) { if (a === b) return true; if (a && b && typeof a == 'object' && typeof b == 'object') { if (a.constructor !== b.constructor) return false; var length, i, keys; if (Array.isArray(a)) { length = a.length; if (length != b.length) return false; for (i = length; i-- !== 0;) if (!equal(a[i], b[i])) return false; return true; } if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); keys = Object.keys(a); length = keys.length; if (length !== Object.keys(b).length) return false; for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; for (i = length; i-- !== 0;) { var key = keys[i]; if (!equal(a[key], b[key])) return false; } return true; } // true if both NaN, false otherwise return a!==a && b!==b; }; // 1 level deep var data = [ { description: 'equal numbers', value1: 1, value2: 1, equal: true, }, { description: 'not equal numbers', value1: 1, value2: 2, equal: false, }, { description: 'number and array are not equal', value1: 1, value2: [], equal: false, }, { description: '0 and null are not equal', value1: 0, value2: null, equal: false, }, { description: 'equal strings', value1: 'a', value2: 'a', equal: true, }, { description: 'big object', value1: { prop1: 'value1', prop2: 'value2', prop3: 'value3', prop4: { subProp1: 'sub value1', subProp2: { subSubProp1: 'sub sub value1', subSubProp2: [ 1, 2, { prop2: 1, prop: 2 }, 4, 5, ], }, }, prop5: 1000, prop6: new Date(2016, 2, 10), }, value2: { prop5: 1000, prop3: 'value3', prop1: 'value1', prop2: 'value2', prop6: new Date('2016/03/10'), prop4: { subProp2: { subSubProp1: 'sub sub value1', subSubProp2: [ 1, 2, { prop2: 1, prop: 2 }, 4, 5, ], }, subProp1: 'sub value1', }, }, equal: true, }, ];
Tests:
lodash.isEqual
data.forEach((item) => { _.isEqual(item.value1, item.value2); });
dequal
data.forEach((item) => { dequal.dequal(item.value1, item.value2); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash.isEqual
dequal
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash.isEqual
534560.5 Ops/sec
dequal
2520024.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain the benchmark and its results in detail. **Benchmark Overview** The benchmark compares the performance of two JavaScript libraries: Lodash's `isEqual` function and Dequal. The benchmark consists of 7 test cases, each testing a different scenario for equality checking. **Options Compared** Two options are being compared: 1. **Lodash's `isEqual` function**: This is a general-purpose equality checking function that can handle various data types, including objects, arrays, numbers, and strings. 2. **Dequal**: This is a lightweight equality checking library specifically designed for testing purposes. **Pros and Cons** * **Lodash's `isEqual` function**: + Pros: robust implementation, can handle complex data structures, well-tested. + Cons: larger bundle size (~50KB), might be overkill for simple equality checks. * **Dequal**: + Pros: lightweight (~10KB), specifically designed for testing, easy to use. + Cons: limited features, not as robust as Lodash's implementation. **Other Considerations** Both libraries have different approaches to handling certain data types: * **Objects**: Lodash's `isEqual` function will recursively compare object properties, while Dequal uses a simple reference check. * **Arrays**: Both libraries use a similar approach, but Lodash's implementation is slightly more efficient due to its use of iterators. **Test Case Explanation** Each test case consists of a single JavaScript statement that calls either the `isEqual` function or the `dequal` function on a specific data value. The data values are defined in the benchmark's script preparation code. * **Test cases 1-3**: Test simple equality checks for numbers, strings, and objects. * **Test cases 4-5**: Test equality checks with arrays of different lengths. * **Test case 6**: Tests equality between two complex objects with nested properties. * **Test case 7**: Tests equality between a number and `null`. **Library Descriptions** 1. **Lodash**: Lodash is a popular JavaScript utility library that provides a wide range of functions for common tasks, including string manipulation, array operations, and object transformations. The `isEqual` function is one of its many useful tools. 2. **Dequal**: Dequal is a lightweight equality checking library specifically designed for testing purposes. It's meant to be fast, simple, and easy to use. **Benchmark Results** The latest benchmark results show that: * Dequal performs slightly better than Lodash's `isEqual` function in terms of execution speed. * The differences are relatively small, with Dequal executing about 20-30% faster on average across all test cases. Keep in mind that these results may vary depending on the specific use case and environment.
Related benchmarks:
fast compare test w/lodash 3
lodash deepEqual vs fast-deep-equal v2
lodash.isEqual vs fast-deep-equal vs local
lodash.isEqual vs fast-deep-equal vs stable-hash-compare
lodash.isEqual vs fast-deep-equal vs local 2
Comments
Confirm delete:
Do you really want to delete benchmark?