Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Bench fast-json-patch vs jsondiffpatch icl. Patching
(version: 0)
Comparing performance of:
jsondiffpatch vs FAST JSON-patch
Created:
2 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:
jsondiffpatch
var diff1 = jsondiffpatch.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
jsondiffpatch
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/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
jsondiffpatch
121611.6 Ops/sec
FAST JSON-patch
325457.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JSON patching benchmarks! The provided benchmark measures the performance of two popular libraries for JSON patching: `fast-json-patch` (also known as FAST) and `jsondiffpatch`. The test cases compare the execution speed of these two libraries when applying patches to a sample JSON object. **Test Case 1: jsondiffpatch** In this test case, we use the `jsondiffpatch` library to: 1. Create a difference (`diff`) between two objects (`obj1` and `obj2`) using `jsondiffpatch.diff`. 2. Clone the original object (`obj1`) using `jsondiffpatch.unpatch`, applying the created difference. 3. Revert the patch by applying it again, which is essentially no-op. The purpose of this test case is to measure the performance of creating a patch and then reapplying it, as well as cloning an object. **Test Case 2: FAST JSON-patch** In this test case, we use the `fast-json-patch` library to: 1. Compare the two objects (`obj1` and `obj2`) using `jsonpatch.compare`. 2. Clone the original object (`obj1`) using `jsonpatch.deepClone`. 3. Apply a patch to the cloned object using `jsonpatch.applyPatch`, passing in the result of the comparison. The purpose of this test case is to measure the performance of creating a comparison and then applying it, as well as cloning an object. **Comparison** | Library | Creating Patch | Cloning Object | Applying Patch | | --- | --- | --- | --- | | jsondiffpatch | Yes | No | No (revert patch) | | FAST JSON-patch | No | Yes | Yes | The main difference between the two test cases is how they create and apply patches: * `jsondiffpatch` creates a patch by taking the difference between two objects, which can be time-consuming. It also doesn't provide a way to apply the patch directly. * FAST JSON-patch creates a comparison between two objects, which is faster than creating a patch. However, it requires cloning an object first. **Pros and Cons** **jsondiffpatch:** Pros: * Can create patches using any kind of data structure * Provides a way to revert patches Cons: * Creating patches can be slower compared to comparing objects * Doesn't provide a direct way to apply patches **FAST JSON-patch:** Pros: * Faster than creating patches * Provides a convenient way to clone and apply patches Cons: * Requires cloning an object first, which may add overhead * Limited to comparing objects only **Other Considerations** When choosing between `jsondiffpatch` and FAST JSON-patch, consider the following factors: * **Data structure:** If you're working with complex data structures, `jsondiffpatch` might be a better choice. However, if your data is mostly composed of simple objects, FAST JSON-patch could be more efficient. * **Patch creation speed:** If creating patches is critical for your use case, FAST JSON-patch's faster approach might be beneficial. However, if the patch creation process is not performance-critical, `jsondiffpatch` might provide a safer and more flexible solution. * **Reverting patches:** If you need to frequently revert patches, `jsondiffpatch` provides a convenient way to do so. **Alternatives** Other popular libraries for JSON patching include: 1. **deep-diff**: Similar to `jsondiffpatch`, but with a focus on deep equality checks. 2. **jsonmerge-patch**: A library that allows merging multiple patches into a single patch. 3. **patch-merge**: Another patch merge library that provides a more concise API. Keep in mind that the choice of library ultimately depends on your specific use case and performance requirements.
Related benchmarks:
Bench fast-json-patch vs jsondiffpatch
Bench fast-json-patch vs deep-diff
Bench fast-json-patch apply vs fast-json-patch mutate
structuredClose(myObject) vs JSON.parse(JSON.stringify(myObject))
Comments
Confirm delete:
Do you really want to delete benchmark?