Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.isEqual vs JSON.stringify Equality Comparison for More Complicated Arrays of 1 object each
(version: 1)
Test on isEqual performance
Comparing performance of:
_.isEqual vs JSON.stringify vs JSON.stringify with sorted keys
Created:
10 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
// Test data setup window.fills1 = [ { fill: "#FF5733", type: "SOLID", blendMode: "normal", visible: true, imgUrl: "", scaleFactor: 1, scaleMode: "FIT", uvTransform: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, color: { r: 255, g: 87, b: 51, a: 1 } } ]; window.fills2 = [ { fill: "#FF5733", type: "SOLID", blendMode: "multiply", // Different value here visible: true, imgUrl: "", scaleFactor: 1, scaleMode: "FIT", uvTransform: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, color: { r: 255, g: 87, b: 51, a: 1 } } ]; window.fills3 = JSON.parse(JSON.stringify(window.fills1));
Tests:
_.isEqual
const result12 = _.isEqual(window.fills1, window.fills2); const result13 = _.isEqual(window.fills1, window.fills3); const result23 = _.isEqual(window.fills2, window.fills3); console.log(result12, result13, result23);
JSON.stringify
const result12 = JSON.stringify(window.fills1) === JSON.stringify(window.fills2); const result13 = JSON.stringify(window.fills1) === JSON.stringify(window.fills3); const result23 = JSON.stringify(window.fills2) === JSON.stringify(window.fills3); console.log(result12, result13, result23);
JSON.stringify with sorted keys
const sortedStringify = (obj) => JSON.stringify(obj, Object.keys(obj || {}).sort()); const result12 = sortedStringify(window.fills1) === sortedStringify(window.fills2); const result13 = sortedStringify(window.fills1) === sortedStringify(window.fills3); const result23 = sortedStringify(window.fills2) === sortedStringify(window.fills3); console.log(result12, result13, result23);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.isEqual
JSON.stringify
JSON.stringify with sorted keys
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
_.isEqual
225258.5 Ops/sec
JSON.stringify
206861.6 Ops/sec
JSON.stringify with sorted keys
253263.8 Ops/sec
Related benchmarks:
Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Array of Strings. temp test
Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Array of Strings. temp test fork
fork Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Array of Strings.
Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Array of Strings. (custom)
Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Object
uri1 Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Array of Strings.
Fast deep equal vs JSON.stringify
Lodash.isEqual vs JSON.stringify Equality Comparison for Deep Array of Objects
Lodash.isEqual vs JSON.stringify Equality Deep Comparison for Shallow Array of Strings but comparing to a hardcoded string
Comments
Confirm delete:
Do you really want to delete benchmark?