Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.isEqual vs fast-deep-equal vs stable-hash-compare
(version: 0)
Comparing performance of:
lodash vs fast-deep-equal vs stable-hash-compare
Created:
3 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 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; }; const isUndefined = v => v === undefined const table = new WeakMap(); let counter = 0; const stableHash = (arg) => { const type = typeof arg; const constructor = arg && arg.constructor; const isDate = constructor == Date; let result; let index; if (Object(arg) === arg && !isDate && constructor != RegExp) { result = table.get(arg); if (result) return result; result = ++counter + '~'; table.set(arg, result); if (constructor == Array) { result = '@'; for (index = 0; index < arg.length; index++) { result += stableHash(arg[index]) + ','; } table.set(arg, result); } if (constructor == Object) { result = '#'; const keys = Object.keys(arg).sort(); while (!isUndefined(index = keys.pop())) { if (!isUndefined(arg[index])) { result += index + ':' + stableHash(arg[index]) + ','; } } table.set(arg, result); } } else { result = isDate ? arg.toJSON() : type == 'symbol' ? arg.toString() : type == 'string' ? JSON.stringify(arg) : '' + arg; } return result; }; function compare(currentData, newData) { return stableHash(currentData) == stableHash(newData) } // 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
data.forEach((item) => { _.isEqual(item.value1, item.value2); });
fast-deep-equal
data.forEach((item) => { equal(item.value1, item.value2); });
stable-hash-compare
data.forEach((item) => { compare(item.value1, item.value2) } )
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash
fast-deep-equal
stable-hash-compare
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
800649.0 Ops/sec
fast-deep-equal
2943408.5 Ops/sec
stable-hash-compare
2321613.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Based on the provided data, I will attempt to answer the question. It appears that we are comparing three different equality check functions: `lodash.isEqual`, `fast-deep-equal` (which is also known as `stable-hash-compare`), and `equal`. From the latest benchmark result, we can see that: * `fast-deep-equal` has a lower execution rate than both `lodash.isEqual` and `equal`. * `stable-hash-compare` has a higher execution rate than both `lodash.isEqual` and `equal`. Given this information, it is difficult to determine which function is the fastest in absolute terms. However, based on the benchmark results alone, we can conclude that: * The order of performance from fastest to slowest is: fast-deep-equal ≈ stable-hash-compare > equal * `fast-deep-equal` has a slight edge over `stable-hash-compare`. However, it's essential to note that this conclusion is based solely on the benchmark results and may not reflect the actual performance characteristics of each function in all scenarios. Additionally, the performance differences between these functions might be affected by various factors such as the specific use case, data type, and other external influences. If you would like me to make any further analysis or provide additional insights, please feel free to ask!
Related benchmarks:
fast compare test w/lodash 3
lodash deepEqual vs fast-deep-equal v2
lodash vs fast-equals vs fast-deep-equal
lodash.isEqual vs fast-deep-equal vs local 2
Comments
Confirm delete:
Do you really want to delete benchmark?