<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://kubsite.000webhostapp.com/fast-json-patch.min.js"></script>
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,
}
]
};
var diff1 = jsondiffpatch.diff(obj1, obj2);
/*var objnew = jsonpatch.deepClone(obj1);
// jsondiffpatch.unpatch(objnew, diff1);*/
var diff3 = jsonpatch.compare(obj1, obj2);
/*var objnew = jsonpatch.deepClone(obj1);
jsonpatch.applyPatch(objnew, diff3, false, true);*/
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
jsondiffpatch | |
FAST JSON-patch |
Test name | Executions per second |
---|---|
jsondiffpatch | 20865.4 Ops/sec |
FAST JSON-patch | 92648.7 Ops/sec |
Let's break down the provided benchmark and explain what's being tested, compared, and their pros/cons.
Benchmark Overview
The benchmark measures the performance of two JavaScript libraries: jsondiffpatch
and FAST JSON-patch (also known as jsonpatch). The test case involves comparing two objects (obj1
and obj2
) for differences. Specifically, it checks how quickly each library can compute these differences.
Options Compared
There are three options being compared:
diff()
that computes the differences between two objects.compare()
, which also computes object differences, and applyPatch()
to apply those differences.Pros/Cons of Each Approach
Library Descriptions
Special JS Features/Syntax
None mentioned explicitly in the provided benchmark. However, it's worth noting that jsonpatch
and jsondiffpatch
both rely on the concept of "patches" – a set of operations (additions, deletions, or modifications) to apply to an original object.
Alternative Alternatives
Other alternatives for JSON diffing include:
diff()
function: Another JavaScript library that computes differences between two objects.In summary, the benchmark compares the performance of jsondiffpatch
and FAST JSON-patch libraries in computing object differences. The choice between these libraries depends on your specific use case, with jsondiffpatch offering simplicity at the cost of potentially slower performance and FAST JSON-patch prioritizing efficiency but with a more complex API.