HTML Preparation code:
AخA
 
1
<script src="https://cdn.jsdelivr.net/underscorejs/1.5.1/underscore-min.js"></script>
2
<script>window.underscore = _.noConflict()</script>
3
<script src="https://cdn.jsdelivr.net/lodash/3.10.1/lodash.min.js"></script>
4
<script>window.lodash = _.noConflict()</script>
Script Preparation code:
x
 
var base = {};
base.deepEquals = function(a, b) {
    if (typeof a != typeof b) {
        return false;
    }
    if (typeof a != "object") {
        return a == b;
    }
    if (a instanceof Array) {
        if (!(b instanceof Array)) {
            return false;
        }
        if (a.length != b.length) {
            return false;
        }
        for (var i = 0; i < a.length; i++) {
            if (!base.deepEquals(a[i], b[i])) {
                return false;
            }
        }
        return true;
    }
    var aKeyCount = 0;
    for (var key in a) {
        aKeyCount++;
        if (!(key in b)) {
            return false;
        }
        if (!base.deepEquals(a[key], b[key])) {
            return false;
        }
    }
    var bKeyCount = 0;
    for (var key in b) {
        if (!(key in a)) {
            return false;
        }
        bKeyCount++;
    }
    return aKeyCount == bKeyCount;
};
    Object.prototype.equals = function (x, deep) {
        if (deep) {
            if (x == this) return true;
            var p;
            for (p in this) {
                if (typeof (x[p]) == 'undefined') { return false; }
            }
            for (p in this) {
                if (this[p]) {
                    switch (typeof (this[p])) {
                        case 'object':
                            if (!this[p].equals(x[p])) { return false; } break;
                        case 'function':
                            if (typeof (x[p]) == 'undefined' ||
                      (p != 'equals' && this[p].toString() != x[p].toString()))
                                return false;
                            break;
                        default:
                            if (this[p] != x[p]) { return false; }
                    }
                } else {
                    if (x[p])
                        return false;
                }
            }
            for (p in x) {
                if (typeof (this[p]) == 'undefined') { return false; }
            }
            return true;
        }
        return x == this;
    }
base.stringifyEquals = function(a, b) {
    return JSON.stringify(a) === JSON.stringify(b);
};
a = {
   tableHeight: 50,
   topOffsets: [1, 2, 3, 4, 5]
};
b = {
   tableHeight: 50,
   topOffsets: [1, 2, 3, 4, 5]
};
Tests:
  • deepEquals

     
    base.deepEquals(a, b)
  • stringifyEquals

     
    base.stringifyEquals(a, b)
  • Object.prototype.equals

     
    a.equals(b, true)
  • Lodash isEqual

     
    lodash.isEqual(a,b)
  • underscore isequal

     
    underscore.isEqual(a,b)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    deepEquals
    stringifyEquals
    Object.prototype.equals
    Lodash isEqual
    underscore isequal

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
Chrome 85 on Mac OS X 10.15.6
View result in a separate tab
Test name Executions per second
deepEquals 380236.5 Ops/sec
stringifyEquals 448270.5 Ops/sec
Object.prototype.equals 1116419.6 Ops/sec
Lodash isEqual 1003513.2 Ops/sec
underscore isequal 621719.9 Ops/sec