Deep Equality Overhead Comparison

JavaScript performance comparison

Revision 2 of this test case created by Alexander Tsepkov

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function ՐՏ_Iterable(iterable) {
      if (Array.isArray(iterable) || iterable instanceof String || typeof iterable === "string") {
          return iterable;
      }
      return Object.keys(iterable);
  }
  function eq(a, b) {
      var i;
      if (a === b) {
          return true;
      }
      if (Array.isArray(a) && Array.isArray(b) || a instanceof Object && b instanceof Object) {
          if (a.constructor !== b.constructor || a.length !== b.length) {
              return false;
          }
          if (Array.isArray(a)) {
              for (i = 0; i < len(a); i++) {
                  if (!eq(a[i], b[i])) {
                      return false;
                  }
              }
          } else {
              if (Object.keys(a).length !== Object.keys(b).length) {
                  return false;
              }
              var ՐՏ_Iter3 = ՐՏ_Iterable(a);
              for (var ՐՏ_Index3 = 0; ՐՏ_Index3 < ՐՏ_Iter3.length; ՐՏ_Index3++) {
                  i = ՐՏ_Iter3[ՐՏ_Index3];
                  if (!eq(a[i], b[i])) {
                      return false;
                  }
              }
          }
          return true;
      }
      return false;
  }
  var numA = 1;
  var numB = 1;
  var numC = 2;
  var arrayA = [3, 10, 14, 7];
  var arrayB = [3, 10, 14, 7];
  var arrayC = [9, 11, 20];
  var objectA = {foo: 1, bar: 'baz'};
  var objectB = {foo: 1, bar: 'baz'};
  var objectC = {beer: 99};

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Primitive Positive: Identity
numA === numB
pending…
Primitive Positive: Naive Deep Equality
eq(numA, numB)
pending…
Primitive Positive: RapydScript Deep Equality
numA === numB || typeof numA === "object" && eq(numA, numB)
pending…
Primitive Negative: Identity
numA === numC
pending…
Primitive Negative: Naive Deep Equality
eq(numA, numC)
pending…
Primitive Negative: RapydScript Deep Equality
numA === numC || typeof numA === "object" && eq(numA, numC)
pending…
Object Positive: Naive Deep Equality
eq(objectA, objectB)
pending…
Object Positive: RapydScript Deep Equality
objectA === objectB || typeof objectA === "object" && eq(objectA, objectB)
pending…
Object Negative: Naive Deep Equality
eq(objectA, objectC)
pending…
Object Negative: RapydScript Deep Equality
objectA === objectC || typeof objectA === "object" && eq(objectA, objectC)
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments