<script src="https://cdn.jsdelivr.net/npm/fast-json-patch/dist/fast-json-patch.min.js"></script>
<script type='text/javascript' src="https://cdn.jsdelivr.net/npm/jsondiffpatch/dist/jsondiffpatch.umd.min.js"></script>
var oldObj = {
"content": {
"blocks": {
"block-0": {
"id": "block-0",
"type": "p",
"leafIds": [
"leaf-2"
]
},
"block-1": {
"id": "block-1",
"type": "p",
"leafIds": [
"leaf-3"
]
}
},
"leaves": {
"leaf-2": {
"id": "leaf-2",
"text": "12345"
},
"leaf-3": {
"id": "leaf-3",
"text": "abcde"
},
"leaf-4": {
"id": "leaf-3",
"text": "abcde"
}
},
"blockIds": [
"block-0",
"block-1"
]
},
"selection": {
"isReversed": false,
"isCollapsed": true,
"startEl": "leaf-2",
"endEl": "leaf-2",
"startOffset": 12,
"endOffset": 12
}
}
var newObj = {
"content": {
"blocks": {
"block-0": {
"id": "block-0",
"type": "p",
"leafIds": [
"leaf-2"
]
},
"block-1": {
"id": "block-1",
"type": "p",
"leafIds": [
"leaf-3"
]
}
},
"leaves": {
"leaf-2": {
"id": "leaf-2",
"text": "12345hooba12"
},
"leaf-3": {
"id": "leaf-3",
"text": "abcde"
}
},
"blockIds": [
"block-0",
"block-1"
]
},
"selection": {
"isReversed": false,
"isCollapsed": true,
"startEl": "leaf-2",
"endEl": "leaf-2",
"startOffset": 12,
"endOffset": 12
}
}
var diffs = []
var diff = jsondiffpatch.diff(oldObj, newObj)
diffs.push(diff)
var objnew = JSON.parse(JSON.stringify(oldObj))
jsondiffpatch.patch(oldObj, diff)
var diff = jsonpatch.compare(oldObj, newObj);
diffs.push(diff)
var objnew = JSON.parse(JSON.stringify(oldObj))
jsonpatch.applyPatch(oldObj, diff)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
jsondiffpatch | |
fast-json-patch |
Test name | Executions per second |
---|---|
jsondiffpatch | 148737.4 Ops/sec |
fast-json-patch | 352011.1 Ops/sec |
Overview of the Benchmark
This benchmark compares two JavaScript libraries for diffing and patching JSON data: jsondiffpatch
and fast-json-patch
. The test case involves creating two identical JSON objects, making some changes to one object, and then comparing the differences between the two objects using each library. The results are used to measure the performance of each library.
Options Compared
The benchmark compares the following options:
Pros and Cons of Each Approach
jsondiffpatch:
Pros:
Cons:
fast-json-patch:
Pros:
Cons:
Other Considerations
When choosing between these libraries, consider the following factors:
Library Used in the Test Case
In this benchmark, both libraries are used to compare the differences between two JSON objects. The jsondiffpatch
library is used to compute the diff and patch, while fast-json-patch
is used to apply the patch.
Special JS Features or Syntax
Neither of the libraries uses any special JavaScript features or syntax that would require additional explanation. Both libraries use standard JavaScript functions and APIs to perform their operations.