JS hash vs object instance

JavaScript performance comparison

Test case created by Xav

Info

Verifying the comments re: hash performance compared to object performance with fixed attributes when optimized w/ JIT.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var Obj, hash;
   
    Obj = (function() {
   
      function Obj(x, y, z) {
        this.x = x;
        this.y = y;
        this.z = z;
      }
   
      return Obj;
   
    })();
   
    hash = {};
   
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Hash
hash = {
  x: 1,
  y: 2,
  z: 3
};
 
pending…
Class instance
new Obj(1, 2, 3);
 
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

Add a comment