Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Bench fast-json-patch vs deep-diff
(version: 0)
Comparing performance of:
deep-diff vs FAST JSON-patch
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type='text/javascript' src="https://cdn.jsdelivr.net/npm/jsondiffpatch/dist/jsondiffpatch.umd.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/deep-diff@1/dist/deep-diff.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/fast-json-patch/dist/fast-json-patch.min.js"></script>
Script Preparation code:
obj1= { name: "Argentina", cities: [ { name: 'Buenos Aires', population: 13028000, }, { name: 'Cordoba', population: 1430023, }, { name: 'Rosario', population: 1136286, }, { name: 'Mendoza', population: 901126, }, { name: 'San Miguel de Tucuman', population: 800000, } ] }; obj2= { name: "Argentina", cities: [ { name: 'Cordoba', population: 1430023, }, { name: 'Mendoza', population: 901126, }, { name: 'San Miguel de Tucuman', population: 550000, } ] };
Tests:
deep-diff
var diff1 = DeepDiff.diff(obj1, obj2); /*var objnew = jsonpatch.deepClone(obj1); // jsondiffpatch.unpatch(objnew, diff1);*/
FAST JSON-patch
var diff3 = jsonpatch.compare(obj1, obj2); /*var objnew = jsonpatch.deepClone(obj1); jsonpatch.applyPatch(objnew, diff3, false, true);*/
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
deep-diff
FAST JSON-patch
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
deep-diff
260370.1 Ops/sec
FAST JSON-patch
1187215.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **Benchmark Definition:** The benchmark compares two popular libraries for JSON patching and diffing: `fast-json-patch` (FAST) and `deep-diff`. **Test Case 1: Deep-Diff** * **Library:** `deep-diff` * **Purpose:** Calculates the differences between two objects. * **Pros:** + Easy to use: simple and straightforward API. + Fast execution: uses a efficient algorithm to calculate differences. * **Cons:** + May not be suitable for large datasets due to memory constraints. **Test Case 2: FAST JSON-Patch** * **Library:** `fast-json-patch` * **Purpose:** Creates a patch object that can be applied to an original object, effectively diffing the two objects. * **Pros:** + Suitable for large datasets: uses a efficient algorithm and doesn't require significant memory allocation. + Flexible: allows for customization of the patching process (e.g., deep cloning, ignore certain properties). * **Cons:** + More complex API compared to Deep-Diff. + May have performance issues if not used correctly. **Other Alternatives:** 1. `jsonpatch`: Another popular library for JSON patching and diffing. While it's similar to FAST, it has some differences in its implementation and API. 2. `diff-match-patch`: A lightweight, JavaScript port of the Java library "DiffMatchPatch". It provides a simple way to calculate differences between two strings or objects. **Special JS Features/Syntax:** * **Spread Syntax (`...`):** Used in the benchmark preparation code to define object literals. * **Template Literals (`\r\n`):** Used to format the JSON data in a readable way. **Benchmark Preparation Code Explanation:** The `obj1` and `obj2` variables are created using template literals, which allow for easy formatting of string values (e.g., city names). The `jsonpatch.deepClone()` function is used to create a deep copy of `obj1`, while the `deep-diff.diff()` function calculates the differences between `obj1` and `obj2`. **Other Considerations:** * The benchmark uses a small dataset, which may not be representative of real-world scenarios where datasets can be much larger. * The execution times reported in the latest benchmark result are quite different between the two test cases. This may indicate that FAST JSON-Patch is more efficient for this specific use case, but further testing would be needed to confirm. * The benchmark doesn't account for any potential errors or edge cases that might occur during the diffing process. Overall, both `deep-diff` and `fast-json-patch` are suitable choices depending on the specific requirements of your project. If you need a lightweight, easy-to-use solution for small datasets, Deep-Diff may be the better choice. However, if you're working with large datasets or require more customization options, FAST JSON-Patch is likely the better option.
Related benchmarks:
extend vs cloneDeep vs JSON.*
extend vs cloneDeep vs JSON.*
extend vs cloneDeep vs JSON.*
extend vs cloneDeep vs JSON.*
extend vs cloneDeep vs JSON.*
Comments
Confirm delete:
Do you really want to delete benchmark?