Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS Deep Comparison Performance
(version: 0)
JSON.stringify vs lodash's isEqual
Comparing performance of:
stringify vs isEqual
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash.isequal@4.5.0/index.js"></script>
Script Preparation code:
const a = { bids: [ [41634.5, 0.0], [41641.0, 600000.0], [42285.0, 0.0], [42291.5, 300000.0], [42504.5, 60000.0], [42507.5, 0.0], [42719.0, 0.0], [42719.5, 470742.0], [42725.5, 225000.0], [42734.0, 0.0], [43066.0, 0.0], [43072.5, 225000.0], [43153.0, 0.0], [43153.5, 233493.0], [43159.5, 225000.0], [43167.5, 1998005.0], [43168.0, 0.0], [43168.5, 0.0], [43171.5, 0.0], [43239.0, 80000.0], [43269.5, 250000.0], [43270.5, 0.0], [43285.0, 199.0], [43287.5, 1977.0], [43288.5, 0.0], [43295.5, 0.0], [43327.5, 59340.0], [43333.5, 0.0], [43335.0, 0.0], [43338.5, 20000.0], [43343.5, 10000.0], ], asks: [ [43379.0, 10000.0], [43383.0, 10000.0], [43403.0, 78676.0], [43403.5, 23218.0], [43404.0, 0.0], [43406.5, 450.0], [43427.0, 2086.0], [43430.5, 117604.0], [43431.0, 20000.0], [43437.5, 199999.0], [43445.0, 0.0], [43446.0, 19616.0], [43506.5, 0.0], [43507.0, 140114.0], [43531.0, 0.0], [43593.5, 0.0], [43594.0, 225000.0], [43680.5, 0.0], [43681.0, 300000.0], [43896.5, 485213.0], [43897.0, 0.0], [43897.5, 300000.0], [43911.0, 0.0], [44461.5, 0.0], [44462.0, 400000.0], [45111.0, 0.0], [45112.5, 600000.0], ] } const b = { bids: [ [41634.5, 0.0], [41641.0, 600000.0], [42285.0, 0.0], [42291.5, 300000.0], [42504.5, 60000.0], [42507.5, 0.0], [42719.0, 0.0], [42719.5, 470742.0], [42725.5, 225000.0], [42734.0, 0.0], [43066.0, 0.0], [43072.5, 225000.0], [43153.0, 0.0], [43153.5, 233493.0], [43159.5, 225000.0], [43167.5, 1998005.0], [43168.0, 0.0], [43168.5, 0.0], [43171.5, 0.0], [43239.0, 80000.0], [43269.5, 250000.0], [43270.5, 0.0], [43285.0, 199.0], [43287.5, 1977.0], [43288.5, 0.0], [43295.5, 0.0], [43327.5, 59340.0], [43333.5, 0.0], [43335.0, 0.0], [43338.5, 20000.0], [43343.5, 10000.0], ], asks: [ [43379.0, 10000.0], [43383.0, 10000.0], [43403.0, 78676.0], [43403.5, 23218.0], [43404.0, 0.0], [43406.5, 450.0], [43427.0, 2086.0], [43430.5, 117604.0], [43431.0, 20000.0], [43437.5, 199999.0], [43445.0, 0.0], [43446.0, 19616.0], [43506.5, 0.0], [43507.0, 140114.0], [43531.0, 0.0], [43593.5, 0.0], [43594.0, 225000.0], [43680.5, 0.0], [43681.0, 300000.0], [43896.5, 485213.0], [43897.0, 0.0], [43897.5, 300000.0], [43911.0, 0.0], [44461.5, 0.0], [44462.0, 400000.0], [45111.0, 0.0], [45112.5, 600000.0], ] }
Tests:
stringify
JSON.stringify(window.a) === JSON.stringify(window.b);
isEqual
_.isEqual(window.a, window.b)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
stringify
isEqual
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/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
stringify
4332032.0 Ops/sec
isEqual
5835088.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The problem seems to be related to comparing two large JSON objects using both `JSON.stringify` and the Lodash library's `isEqual` function. To answer your question, I'll provide some general advice on how to compare large JSON objects efficiently: 1. **Use a efficient comparison method**: When dealing with large JSON objects, it's generally faster to use a binary search-based approach or a data structure like a hash table to find the differences between two objects. `JSON.stringify` can be slow because it converts the entire object to a string, which requires parsing and encoding. 2. **Use Lodash's `isEqual` function**: The Lodash library provides an optimized implementation of JSON comparison using a trie-based data structure. This makes it significantly faster than `JSON.stringify`. 3. **Consider using a custom comparison function**: Depending on the specific requirements of your benchmark, you might be able to write a custom comparison function that can take advantage of the object's internal structure and optimize the comparison process. 4. **Minimize overhead**: Make sure to minimize any additional overhead introduced by the comparison function or library. In terms of the code itself, here are some suggestions: **Using `JSON.stringify`**: ```javascript const a = window.a; const b = window.b; // Compare using JSON.stringify if (JSON.stringify(a) !== JSON.stringify(b)) { console.error('Incompatible values'); } ``` **Using Lodash's `isEqual` function**: ```javascript import _ from 'lodash'; const a = window.a; const b = window.b; // Compare using isEqual if (!_.isEqual(a, b)) { console.error('Incompatible values'); } ``` Please note that without the actual code and test data, it's difficult to provide a specific answer. The best approach will depend on the specifics of your use case. If you'd like me to analyze the provided benchmark results or test cases in more detail, I can try to help with that as well!
Related benchmarks:
Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Array of Strings.
Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Array of Strings. Lodash v 4.17.11
Lodash.isEqual vs JSON.stringify Equality Comparison for deep objects.
Lodash.isEqual vs JSON.stringify Equality Comparison for Shallow Array of Strings. Testing 123
Lodash.isEqual vs JSON.stringify Equality Comparison for 1000 length array
Comments
Confirm delete:
Do you really want to delete benchmark?