<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>
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)
DeepDiff(beforeText, afterText)
MongoDBDiff.diff(beforeText, afterText)
MongoDBDiff.diff(beforeTextI.toJS(), afterTextI.toJS())
idiff(beforeTextI, afterTextI)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
DeepDiff (beforeText, afterText) | |
MongoDBDiff.diff(beforeText, afterText) | |
MongoDBDiff.diff *.toJS() | |
ImmutableDiff two mostly shared objects |
Test name | Executions per second |
---|---|
DeepDiff (beforeText, afterText) | 38981.0 Ops/sec |
MongoDBDiff.diff(beforeText, afterText) | 35049.1 Ops/sec |
MongoDBDiff.diff *.toJS() | 20924.8 Ops/sec |
ImmutableDiff two mostly shared objects | 109612.8 Ops/sec |
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:
Pros and Cons of each approach:
Other considerations:
beforeTextI
) suggests that the test case is interested in exploring different strategies for computing diffs between immutable data structures.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:
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.