ExtendingNull

JavaScript performance comparison

Test case created by jfet97

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
   class Hash {
      get length() {
        return Object.keys(this).length;
      }
  
      clear() {
        Object.keys(this).forEach( key => delete this[key]);
      }
  
      *[Symbol.iterator]() {
        const entries = Object.entries(this);
  
        for (const entry of entries) yield entry;
      } 
  }
  
  class HashNull extends null {
      constructor() {
           return Object.create(HashNull.prototype)
      }
  
      get length() {
        return Object.keys(this).length;
      }
  
      clear() {
        Object.keys(this).forEach( key => delete this[key]);
      }
  
      *[Symbol.iterator]() {
        const entries = Object.entries(this);
  
        for (const entry of entries) yield entry;
      } 
  }
  
  const howMany = 5000;
  
  // write test
  function setHash(hash) {
      Array(howMany).fill().forEach((_,i) => hash[i] = i);
  }
  
  // read test
  function getHash(hash) {
      Array(howMany).fill().forEach((_,i) => hash[i]);
  }
  

};
</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
null
const hashnull = new HashNull;

Array(50).forEach( () => { setHash(hashnull); getHash(hashnull); hashnull.clear(); });
pending…
not null
const hash = new Hash;

Array(50).forEach( () => { setHash(hash); getHash(hash); hash.clear(); });
pending…

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

Compare results of other browsers

0 Comments