HTML Preparation code:
AخA
 
1
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
x
 
function is(x, y) {
    if (x === y) {
        return x !== 0 || y !== 0 || 1 / x === 1 / y;
    }
    return x !== x && y !== y;
}
function shallowEqual(objA, objB) {
    if (is(objA, objB)) return true;
    if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
        return false;
    }
    const keysA = Object.keys(objA);
    const keysB = Object.keys(objB);
    if (keysA.length !== keysB.length) return false;
    for (let i = 0; i < keysA.length; i++) {
        if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
            return false;
        }
    }
    return true;
}
// 1 level deep
window.foo1 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2 } } };
window.bar1 = { a: 1, b: 3, c: { a: 1, b: 2, c: { a: 1, b: 2 } } };
// 2 levels deep
window.foo2 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2 } } };
window.bar2 = { a: 1, b: 2, c: { a: 1, b: 3, c: { a: 1, b: 2 } } };
// 3 levels deep
window.foo3 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2 } } };
window.bar3 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 4 } } };
Tests:
  • _.isEqual Level 1

     
    _.isEqual(window.foo1, window.bar1)
  • JSON.stringify Level 1

     
    JSON.stringify(window.foo1) === JSON.stringify(window.bar1);
  • _.isEqual Level 2

     
    _.isEqual(window.foo2, window.bar2)
  • JSON.stringify Level 2

     
    JSON.stringify(window.foo2) === JSON.stringify(window.bar2);
  • _.isEqual Level 3

     
    _.isEqual(window.foo3, window.bar3)
  • JSON.stringify Level 3

     
    JSON.stringify(window.foo3) === JSON.stringify(window.bar3);
  • shallowEqual Level 1

     
    shallowEqual(window.foo1, window.bar1)
  • shallowEqual Level 2

     
    shallowEqual(window.foo2, window.bar2)
  • shallowEqual Level 3

     
    shallowEqual(window.foo3, window.bar3)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    _.isEqual Level 1
    JSON.stringify Level 1
    _.isEqual Level 2
    JSON.stringify Level 2
    _.isEqual Level 3
    JSON.stringify Level 3
    shallowEqual Level 1
    shallowEqual Level 2
    shallowEqual Level 3

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Chrome 112 on Linux
View result in a separate tab
Test name Executions per second
_.isEqual Level 1 1122187.6 Ops/sec
JSON.stringify Level 1 633716.8 Ops/sec
_.isEqual Level 2 692744.5 Ops/sec
JSON.stringify Level 2 634989.9 Ops/sec
_.isEqual Level 3 525239.0 Ops/sec
JSON.stringify Level 3 646595.5 Ops/sec
shallowEqual Level 1 1310119.5 Ops/sec
shallowEqual Level 2 1026650.6 Ops/sec
shallowEqual Level 3 1025201.1 Ops/sec