objectsEqual

JavaScript performance comparison

Test case created by Paratron

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const objectsEqualA = (objA, objB) => JSON.stringify(objA) === JSON.stringify(objB);
  
  const objectsEqualB = (objA, objB) => {
      const objAKeys = Object.keys(objA).sort();
      const objBKeys = Object.keys(objB).sort();
  
      if (objAKeys.length !== objBKeys.length) {
          return false;
      }
  
      for (let i = 0; i < objAKeys.length; i++) {
          if (objAKeys[i] !== objBKeys[i]) {
              return false;
          }
          const key = objAKeys[i];
  
          if (objA[key] !== objB[key]) {
              return false;
          }
      }
      return true;
  };
  
  const o1 = {ameise: 'hallo', banane: 'welt', 'chameleon-drama': 'bla'};
  const o2 = {nest: 'vogel', was: 'auch immer'};

};
</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
Test method A (JSON.stringify)
objectsEqualA(o1, o2);
pending…
Test method B (functional approach))
objectsEqualB(o1, o2);
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