HTML Preparation code:
x
 
1
<script src="https://cdn.jsdelivr.net/npm/fast-json-patch@3.1.1/dist/fast-json-patch.min.js"></script>
2
<script>
3
  // Add this in your benchmark setup code
4
function diff(t,e,r={cyclesFix:!0},s=[]){
5
  const richTypes={Date:!0,RegExp:!0,String:!0,Number:!0};
6
  let a=[];
7
  const c=Array.isArray(t);
8
  for(const i in t){
9
    const o=t[i],n=c?+i:i;
10
    if(!(i in e)){a.push({type:"REMOVE",path:[n],oldValue:t[i]});continue}
11
    const p=e[i],y="object"==typeof o&&"object"==typeof p&&Array.isArray(o)===Array.isArray(p);
12
    !(o&&p&&y)||richTypes[Object.getPrototypeOf(o)?.constructor?.name]||r.cyclesFix&&s.includes(o)?o===p||Number.isNaN(o)&&Number.isNaN(p)||y&&(isNaN(o)?o+""==p+"":+o==+p)||a.push({path:[n],type:"CHANGE",value:p,oldValue:o}):a.push.apply(a,diff(o,p,r,r.cyclesFix?s.concat([o]):[]).map((t=>(t.path.unshift(n),t))))
13
  }
14
  const i=Array.isArray(e);
15
  for(const r in e)r in t||a.push({type:"CREATE",path:[i?+r:r],value:e[r]});
16
  return a
17
}
18
19
// Now you can use 'diff' in your benchmark tests
20
</script>
21
22
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:
  • microdiff

     
    var diff1 = 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>

Previous results

Experimental features:

  • Test case name Result
    microdiff
    FAST JSON-patch

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 29 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133 on Windows
View result in a separate tab
Test name Executions per second
microdiff 318247.4 Ops/sec
FAST JSON-patch 1635221.1 Ops/sec