Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Bench fast-json-patch apply vs fast-json-patch mutate
(version: 0)
Comparing performance of:
FAST JSON-patch no mutate vs FAST JSON-patch mutate
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<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:
FAST JSON-patch no mutate
var diff3 = jsonpatch.compare(obj1, obj2); var objnew = jsonpatch.deepClone(obj1); jsonpatch.applyPatch(objnew, diff3, false, false);
FAST JSON-patch mutate
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
FAST JSON-patch no mutate
FAST JSON-patch mutate
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/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
FAST JSON-patch no mutate
222420.1 Ops/sec
FAST JSON-patch mutate
280484.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what is being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark measures the performance of two different approaches for applying patches to JSON objects using the `fast-json-patch` library. **Approaches Compared** 1. **`jsonpatch.applyPatch(objnew, diff3, false, true)`**: This approach creates a deep clone of the original object (`objnew`) and then applies the patch from `diff3` to it without mutating the cloned object. 2. **`jsonpatch.applyPatch(objnew, diff3, false, false)`**: This approach is similar to the previous one, but it mutates the cloned object instead of creating a new one. **Pros and Cons** * **Creating a deep clone**: Creating a deep clone of the original object can be beneficial for certain use cases where data integrity is crucial. However, this approach may incur additional overhead due to the cloning process. + Pros: Ensures data integrity, avoids mutation of original objects. + Cons: May incur additional overhead, creates an extra copy of the object. * **Mutating the cloned object**: Applying the patch directly to the cloned object can be faster since it doesn't require creating a new copy. + Pros: Faster, avoids extra copying. + Cons: Mutates the original object if not used carefully. **Library and Purpose** `fast-json-patch` is a lightweight JavaScript library that provides methods for comparing and manipulating JSON objects using JSON Patch. The `applyPatch()` method applies a patch to an object, either mutating it in-place or creating a new copy. In this benchmark, the `fast-json-patch` library is used to compare two JSON objects (`obj1` and `obj2`) and apply patches to create a new object with the desired changes. **Special JS Feature** This benchmark does not use any special JavaScript features like async/await, let/catch blocks, or modern syntax. It only uses standard JavaScript syntax for creating and manipulating JSON objects. **Alternative Approaches** Other approaches for applying patches to JSON objects include: * Using a library like Lodash's `mergeDeep()` method. * Implementing custom patch application logic using recursion or iteration. * Using a different patch format, such as JSON Patch with additional metadata. However, these alternatives may have different performance characteristics and trade-offs compared to the approaches used in this benchmark.
Related benchmarks:
extend vs cloneDeep vs JSON.*
extend vs cloneDeep vs JSON.*
extend vs cloneDeep vs JSON.*
Lodash benchmark (Anton)
cloneDeep vs JSON stringify + parse (long arr)
Comments
Confirm delete:
Do you really want to delete benchmark?