Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
deep comparsions
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
deepequal
71374.2 Ops/sec
isEqual
34942.6 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
// Unsorted Array number var object1 = { a: 1, b: { c: 2, d: [3, 4], }, }; var object2 = { a: 1, b: { c: 2, d: [4, 3], }, }; // Unsorted Array of objects var object3 = { a: 1, b: { c: 2, d: [{ w: 123 }, { x: 444 }], }, }; var object4 = { a: 1, b: { c: 2, d: [{ x: 444 }, { w: 123 }], }, }; // unsorted Array of Arrays of numbers var object5 = { a: 1, b: { c: 2, d: [ [1, 2, 3], [4, 5, 6], ], }, }; var object6 = { a: 1, b: { c: 2, d: [ [4, 5, 6], [1, 2, 3], ], }, };
Tests:
deepequal
const deepEqual = (obj1, obj2) => { if (obj1 === obj2) return true; if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null) { return false; } if (Array.isArray(obj1) && Array.isArray(obj2)) { if (obj1.length !== obj2.length) return false; obj1 = obj1.slice().sort(); obj2 = obj2.slice().sort(); return obj1.every((value, index) => deepEqual(value, obj2[index])); } if (Array.isArray(obj1) !== Array.isArray(obj2)) { return false; } const keys1 = Object.keys(obj1); const keys2 = Object.keys(obj2); if (keys1.length !== keys2.length) return false; keys1.sort(); keys2.sort(); return keys1.every((key, index) => { if (key !== keys2[index]) return false; return deepEqual(obj1[key], obj2[key]); }); } console.log(deepEqual(object1, object2)); // true console.log(deepEqual(object3, object4)); // false console.log(deepEqual(object5, object6)); // true
isEqual
const customizer = (objValue, othValue) => { if (_.isArray(objValue) && _.isArray(othValue)) { return _.isEqual(deepSort(objValue), deepSort(othValue)); } }; const deepSort = (obj) => { if (_.isArray(obj)) { return _.sortBy(obj.map(deepSort), (item) => JSON.stringify(item)); } else if (_.isObject(obj)) { return _.keys(obj) .sort() .reduce((result, key) => { result[key] = deepSort(obj[key]); return result; }, {}); } return obj; }; console.log(_.isEqualWith(object1, object2, customizer)); // true console.log(_.isEqualWith(object3, object4, customizer)); // true console.log(_.isEqualWith(object5, object6, customizer)); // true