<script src="https://cdn.jsdelivr.net/npm/fast-json-patch/dist/fast-json-patch.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/deep-diff/1.0.2/deep-diff.min.js" integrity="sha512-sKpj+p1Vl1GH12VgyCSFdaz5+yjKfd2z10v2G/l1ZeUNN91hZO2NuzuQeCw8ynaLCdYSXanLEekKRWxeqdXU5Q==" crossorigin="anonymous"></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"
}
},
"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 = DeepDiff.diff(newObj, oldObj)
diffs.push(diff)
var diff = jsonpatch.compare(oldObj, newObj);
diffs.push(diff)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
deep-diff | |
json-fast-patch |
Test name | Executions per second |
---|---|
deep-diff | 214283.5 Ops/sec |
json-fast-patch | 406659.5 Ops/sec |
Let's break down the provided benchmark and explain what is being tested.
Benchmark Overview
The benchmark compares two JavaScript libraries: json-fast-patch
and deep-diff
. The goal is to determine which library is faster for making JSON patches.
Options Compared
There are two options compared:
Pros and Cons of Each Approach
json-fast-patch:
Pros:
Cons:
deep-diff:
Pros:
Cons:
Library Descriptions
Special JS Features or Syntax
Neither of the libraries used in this benchmark relies on any special JavaScript features or syntax beyond standard ECMAScript.
Other Alternatives
If you're looking for alternative JSON patching libraries, some popular options include:
In summary, the benchmark compares two JavaScript libraries: json-fast-patch
and deep-diff
. The choice between these libraries depends on your specific requirements, including the complexity of your JSON structures, performance needs, and error handling requirements.