Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Different Styles of Object Diffs in JS
(version: 10)
Comparing performance of:
DeepDiff (beforeText, afterText) vs MongoDBDiff.diff(beforeText, afterText) vs MongoDBDiff.diff *.toJS() vs ImmutableDiff two mostly shared objects
Created:
9 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.1/immutable.min.js'></script> <script src='https://s3.amazonaws.com/www.deanius.com/javascripts/mongodb-diff.umd.js'></script> <script src='https://s3.amazonaws.com/www.deanius.com/javascripts/immutablediff.umd.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/deep-diff/0.3.3/deep-diff.min.js'></script>
Script Preparation code:
var beforeText = {"_id":"DZqGmqL6T9TBN6KXp","title":"Foofoo","createdAt":1475201145611,"createdBy":"Pe92xcgNnbi3yAebn","updatedBy":"Pe92xcgNnbi3yAebn","updatedAt":1475201156823,"artifactType":"creation","type":"canvas","status":"active","pages":[{"title":"Page 1","_id":"NMGnvMihjvB4XxZa7","createdAt":1475201145612,"items":{"_order":["dsbDxZQr7zMZ9JKYF"],"dsbDxZQr7zMZ9JKYF":{"_id":"dsbDxZQr7zMZ9JKYF","version":"1.0.0","style":{"text_align":"center","padding_left":12,"padding_right":12,"padding_top":28,"padding_bottom":28,"opacity":1},"settings":{"subtitle":false},"type":"headline","text":{"en":{"text":"<p>The word</p>"}}}}}],"settings":{"viewType":"free-form"}}; var afterText = {"_id":"DZqGmqL6T9TBN6KXp","title":"Foofoo","createdAt":1475201145611,"createdBy":"Pe92xcgNnbi3yAebn","updatedBy":"Pe92xcgNnbi3yAebn","updatedAt":1475201226516,"artifactType":"creation","type":"canvas","status":"active","pages":[{"title":"Page 1","_id":"NMGnvMihjvB4XxZa7","createdAt":1475201145612,"items":{"_order":["dsbDxZQr7zMZ9JKYF","J7y7NPf2WWema4sjy"],"dsbDxZQr7zMZ9JKYF":{"_id":"dsbDxZQr7zMZ9JKYF","version":"1.0.0","style":{"text_align":"center","padding_left":12,"padding_right":12,"padding_top":28,"padding_bottom":28,"opacity":1},"settings":{"subtitle":false},"type":"headline","text":{"en":{"text":"<p>The word</p>"}}},"J7y7NPf2WWema4sjy":{"_id":"J7y7NPf2WWema4sjy","version":"1.0.0","style":{"padding_left":12,"padding_right":12,"padding_top":18,"padding_bottom":18},"settings":{"title":false,"description":false,"caption":false},"type":"text","text":{"en":{"text":"<p>My first text</p>"}}}}}],"settings":{"viewType":"free-form"}}; var newEl = {"_id":"J7y7NPf2WWema4sjy","version":"1.0.0","style":{"padding_left":12,"padding_right":12,"padding_top":18,"padding_bottom":18},"settings":{"title":false,"description":false,"caption":false},"type":"text","text":{"en":{"text":"<p>My first text</p>"}}} var beforeTextI = Immutable.fromJS(beforeText); var afterTextI = beforeTextI.setIn(['items', 'J7y7NPf2WWema4sjy'], newEl)
Tests:
DeepDiff (beforeText, afterText)
DeepDiff(beforeText, afterText)
MongoDBDiff.diff(beforeText, afterText)
MongoDBDiff.diff(beforeText, afterText)
MongoDBDiff.diff *.toJS()
MongoDBDiff.diff(beforeTextI.toJS(), afterTextI.toJS())
ImmutableDiff two mostly shared objects
idiff(beforeTextI, afterTextI)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
DeepDiff (beforeText, afterText)
MongoDBDiff.diff(beforeText, afterText)
MongoDBDiff.diff *.toJS()
ImmutableDiff two mostly shared objects
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):
Let's break down the provided benchmark definition and explanation. **What is being tested?** The test cases are designed to compare different approaches for computing object diffs in JavaScript. The inputs are two JSON objects: `beforeText` and `afterText`. These objects represent before-and-after states of some kind, likely related to a web application. The objective is to find the most efficient way to determine what has changed between these two states. **Options being compared:** 1. **DeepDiff**: A library that provides a deep diff algorithm for JavaScript objects. 2. **MongoDBDiff**: Another library specifically designed for computing diffs in MongoDB-style documents (i.e., JSON-like with nested structures). 3. **idiff**: A library that performs incremental diffing between two immutable data structures. **Pros and Cons of each approach:** 1. **DeepDiff**: * Pros: Robust, widely-used, and well-maintained. * Cons: May be slower than other approaches for very large objects or complex data structures. 2. **MongoDBDiff**: * Pros: Optimized for MongoDB-style documents, which are common in web applications. * Cons: May not be as efficient as DeepDiff for general-purpose object diffs. 3. **idiff**: * Pros: Designed specifically for incremental diffing, making it potentially faster than other approaches. * Cons: May require additional setup and understanding of immutable data structures. **Other considerations:** * The use of Immutable.js library (`beforeTextI`) suggests that the test case is interested in exploring different strategies for computing diffs between immutable data structures. * The `toJS()` method is used to convert Immutable.js objects to regular JavaScript objects, which allows for a more direct comparison with other libraries. **Other alternatives:** Some other libraries and approaches worth mentioning include: 1. **diff**: A lightweight library that provides basic diffing functionality. 2. **ObjectDiffer**: Another popular library for computing object diffs. 3. **Lodash.diff**: A utility function from the Lodash library that can be used for diffing. These alternatives may not be as well-maintained or widely adopted as some of the libraries mentioned above, but they still provide a solid foundation for exploring different strategies for computing object diffs.
Related benchmarks:
lodash merge vs object.assign vs spread 2
Classnames@2.3.1 vs clsx@1.1.1
Random perf
another classnames vs clsx
Comments
Confirm delete:
Do you really want to delete benchmark?