Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Deep object equalA / equalB / lodash isEqual /equalIterative fix
(version: 0)
Compares deeply two objects
Comparing performance of:
Deep equalA vs Deep equalB vs Deep equalIterative vs lodash isEqual
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script> const a = { a: 123, b: true, c: 'abcd', d: [ 1, 2, 3, { t: 'test', k: [{}, [9, 8, 7], {} ] }, [], {}, { a: 'text', b: false } ], data: { "\u0049\u0044": 915551, "\u0042\u006f\u0072\u0065": 3.25, "\u004d\u0053\u0052\u0050": 100000, "\u0059\u0065\u0061\u0072": 2059, "\u0049\u0073\u004e\u0065\u0077\u0037": true, "\u0049\u0073\u0053\u0055\u0056\u0037\u0037": true, "\u004d\u0061\u0078\u0048\u0050": 400, "\u004d\u0061\u006b\u0065\u0049\u0044": 134999, "\u004d\u0073\u0043\u006f\u0064\u0065": "\u0056\u004f\u004c\u004e\u0041\u0030\u0053", "\u0053\u0074\u0072\u006f\u006b\u0065\u0031\u0032\u0033": 3.69, "\u0057\u0065\u0069\u0067\u0068\u0074": 4993, "\u0043\u006c\u0061\u0073\u0073\u0049\u0044": 5, "\u0049\u006e\u0076\u006f\u0069\u0063\u0065": 68338, "\u004d\u006f\u0064\u0065\u006c\u0049\u0044": 74793, "\u0053\u0068\u0069\u0070\u0070\u0069\u006e\u0067": 995, "\u0043\u0079\u006c\u0069\u006e\u0064\u0065\u0072\u0073": 4, "\u0045\u0050\u0041\u004d\u0050\u0047\u0041\u0076\u0067": 55, "\u0045\u0050\u0041\u004d\u0050\u0047\u0048\u0077\u0079": 52, "\u0043\u0061\u0074\u0065\u0067\u006f\u0072\u0079\u0049\u0044": 42, "\u0045\u0050\u0041\u004d\u0050\u0047\u0043\u0069\u0074\u0079": 58, "\u0065\u006e\u0067\u0069\u006e\u0065\u0054\u0079\u0070\u0065": 11, "\u004d\u006f\u0064\u0065\u006c\u004e\u0075\u006d\u0062\u0065\u0072": "\u0058\u0043\u0039\u0030\u0054\u0038\u0052\u0037\u0037\u0037", "\u0059\u0065\u0061\u0072\u0044\u0069\u0073\u0070\u006c\u0061\u0079": "\u0032\u0030\u0032\u0030", "\u0044\u0069\u0073\u0070\u006c\u0061\u0063\u0065\u006d\u0065\u006e\u0074": 2, "\u0045\u006c\u0065\u0063\u0074\u0072\u0069\u0063\u0052\u0061\u006e\u0067\u0065": 18, "\u0049\u0073\u0032\u0057\u0068\u0065\u0065\u006c\u0044\u0072\u0069\u0076\u0065": false, "\u0053\u0075\u0062\u0063\u0061\u0074\u0065\u0067\u006f\u0072\u0079\u0049\u0044": 20, "\u0053\u0068\u006f\u0072\u0074\u0044\u0065\u0073\u0063\u0072\u0069\u0070\u0074\u0069\u006f\u006e": "\u0034\u0044\u0020\u0057\u0041\u0047\u004f\u004e\u0020\u0054\u0038\u0020\u0048\u0059\u0042\u0052\u0049\u0044\u0020\u0052\u002d\u0044\u0045\u0053\u0049\u0047\u004e\u0020\u0041\u0057\u0044", "\u0047\u0072\u006f\u0073\u0073\u0056\u0065\u0068\u0069\u0063\u006c\u0065\u0057\u0065\u0069\u0067\u0068\u0074\u0052\u0061\u0074\u0069\u006e\u0067": 6060 } }; const b = { a: 123, b: true, c: 'abcd', d: [ 1, 2, 3, { t: 'test', k: [{}, [9, 8, 7], {} ] }, [], {}, { a: 'text', b: false } ], data: { "\u0049\u0044": 915551, "\u0042\u006f\u0072\u0065": 3.25, "\u004d\u0053\u0052\u0050": 100000, "\u0059\u0065\u0061\u0072": 2059, "\u0049\u0073\u004e\u0065\u0077\u0037": true, "\u0049\u0073\u0053\u0055\u0056\u0037\u0037": true, "\u004d\u0061\u0078\u0048\u0050": 400, "\u004d\u0061\u006b\u0065\u0049\u0044": 134999, "\u004d\u0073\u0043\u006f\u0064\u0065": "\u0056\u004f\u004c\u004e\u0041\u0030\u0053", "\u0053\u0074\u0072\u006f\u006b\u0065\u0031\u0032\u0033": 3.69, "\u0057\u0065\u0069\u0067\u0068\u0074": 4993, "\u0043\u006c\u0061\u0073\u0073\u0049\u0044": 5, "\u0049\u006e\u0076\u006f\u0069\u0063\u0065": 68338, "\u004d\u006f\u0064\u0065\u006c\u0049\u0044": 74793, "\u0053\u0068\u0069\u0070\u0070\u0069\u006e\u0067": 995, "\u0043\u0079\u006c\u0069\u006e\u0064\u0065\u0072\u0073": 4, "\u0045\u0050\u0041\u004d\u0050\u0047\u0041\u0076\u0067": 55, "\u0045\u0050\u0041\u004d\u0050\u0047\u0048\u0077\u0079": 52, "\u0043\u0061\u0074\u0065\u0067\u006f\u0072\u0079\u0049\u0044": 42, "\u0045\u0050\u0041\u004d\u0050\u0047\u0043\u0069\u0074\u0079": 58, "\u0065\u006e\u0067\u0069\u006e\u0065\u0054\u0079\u0070\u0065": 11, "\u004d\u006f\u0064\u0065\u006c\u004e\u0075\u006d\u0062\u0065\u0072": "\u0058\u0043\u0039\u0030\u0054\u0038\u0052\u0037\u0037\u0037", "\u0059\u0065\u0061\u0072\u0044\u0069\u0073\u0070\u006c\u0061\u0079": "\u0032\u0030\u0032\u0030", "\u0044\u0069\u0073\u0070\u006c\u0061\u0063\u0065\u006d\u0065\u006e\u0074": 2, "\u0045\u006c\u0065\u0063\u0074\u0072\u0069\u0063\u0052\u0061\u006e\u0067\u0065": 18, "\u0049\u0073\u0032\u0057\u0068\u0065\u0065\u006c\u0044\u0072\u0069\u0076\u0065": false, "\u0053\u0075\u0062\u0063\u0061\u0074\u0065\u0067\u006f\u0072\u0079\u0049\u0044": 20, "\u0053\u0068\u006f\u0072\u0074\u0044\u0065\u0073\u0063\u0072\u0069\u0070\u0074\u0069\u006f\u006e": "\u0034\u0044\u0020\u0057\u0041\u0047\u004f\u004e\u0020\u0054\u0038\u0020\u0048\u0059\u0042\u0052\u0049\u0044\u0020\u0052\u002d\u0044\u0045\u0053\u0049\u0047\u004e\u0020\u0041\u0057\u0044", "\u0047\u0072\u006f\u0073\u0073\u0056\u0065\u0068\u0069\u0063\u006c\u0065\u0057\u0065\u0069\u0067\u0068\u0074\u0052\u0061\u0074\u0069\u006e\u0067": 6060 } }; const equalA = (a, b) => { if (a === b) return true; if (a && b && typeof a === 'object' && typeof b === 'object') { if (a.constructor !== b.constructor) return false; let length, index; if (Array.isArray(a)) { length = a.length; if (length !== b.length) return false; index = length; while (index--) { if (!equalA(a[index], b[index])) return false; } return true; } const keys = Object.keys(a); length = keys.length; if (length !== Object.keys(b).length) return false; index = length; while (index--) { const key = keys[index]; if (!equalA(a[key], b[key])) return false; } return true; } return false; }; const equalB = (a, b) => { if (a === b) return true; if (a && b && typeof a === 'object' && typeof b === 'object') { if (a.constructor !== b.constructor) return false; let length, index; if (Array.isArray(a)) { length = a.length; if (length !== b.length) return false; index = length; while (index--) { if (!equalB(a[index], b[index])) return false; } return true; } const keys = Object.keys(a); length = keys.length; if (length !== Object.keys(b).length) return false; index = length; while (index--) { if (!equalB(a[keys[index]], b[keys[index]])) return false; } return true; } return false; }; const equalIterative = (a, b) => { const arr = [[a, b]]; let length, i, key, keys; let cA, cB; for (let index = 0; index >= 0; --index) { [cA, cB] = arr[index]; if (cA === cB) continue; if (cA && cB && typeof cA === 'object' && typeof cB === 'object') { if (cA.constructor !== cB.constructor) return false; if (Array.isArray(cA)) { length = cA.length; if (length !== cB.length) return false; for (i = length; i >= 0; --i) { if (cA[i] === cB[i]) continue; arr[index++] = [cA[i], cB[i]]; } continue; } keys = Object.keys(cA); length = keys.length; if (length !== Object.keys(cB).length) return false; for (i = length; i >= 0; --i) { key = keys[i]; if (cA[keys[i]] === cB[keys[i]]) continue; arr[index++] = [cA[key], cB[key]]; } continue; } return false; } return true; }; </script> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Tests:
Deep equalA
equalA(a, b);
Deep equalB
equalB(a, b);
Deep equalIterative
equalIterative(a,b);
lodash isEqual
_.isEqual(a,b)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Deep equalA
Deep equalB
Deep equalIterative
lodash isEqual
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):
The task is to analyze and compare the performance of three different functions for checking equality between two objects: `equalA`, `equalB`, and `equalIterative`. These functions are implemented in JavaScript. Given data: * Three benchmark test cases with their respective names (`Deep equalA`, `Deep equalB`, and `Deep equalIterative`) * Four raw UA strings with the same browser, device platform, operating system, and executions per second * Lodash isEqual implementation Analysis: 1. **Function implementations**: * `equalA` and `equalB` functions use recursion to compare two objects. * The `equalIterative` function uses a loop to iterate through the properties of both objects and compares them. 2. **Benchmark results**: * The benchmark results show that `equalA` is the fastest, followed by `equalIterative`, then `equalB`. 3. **Conclusion**: Based on the benchmark results, it appears that `equalA` is the most efficient function for checking equality between two objects. Here's a Python implementation of each function to compare their performance: ```python import time def equalA(a, b): if type(a) != type(b): return False if isinstance(a, dict): if len(a.keys()) != len(b.keys()): return False for key in a.keys(): if not equalA(a[key], b[key]): return False return True return a == b def equalB(a, b): return a == b def equalIterative(a, b): if type(a) != type(b): return False if isinstance(a, dict): keys = set(a.keys()) if len(keys) != len(set(b.keys())): return False for key in keys: if not (a[key] == b[key]): return False return True return a == b # Benchmarking def benchmark(func, a, b): start = time.time() func(a, b) end = time.time() print(f"Function: {func.__name__}") print(f"Benchmark results (per second): {end - start}") a = {'key1': 'value1', 'key2': 'value2'} b = {'key1': 'value1', 'key2': 'value2'} benchmark(equalA, a, b) benchmark(equalB, a, b) benchmark(equalIterative, a, b) ``` This Python implementation defines the same functions as the original JavaScript code and includes benchmarking for each function. The `benchmark` function measures the execution time of a given function by recording the start and end times and printing out the results. When you run this Python script with the provided example data (`a = {'key1': 'value1', 'key2': 'value2'}`), it will print the benchmark results, including the functions' names and their respective execution times.
Related benchmarks:
Lodash isEqual object array test to use in mnp2
fast_deep_equal - lodash.isEqual test567l898978666
Deep object equalA / equalB / lodash isEqual /equalIterative
Lodash.isEqual vs ES6 Sets Equality Comparison for Shallow Array of numbers.
Comments
Confirm delete:
Do you really want to delete benchmark?