JS hash vs object instance

JavaScript performance comparison

Test case created by Xav


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

Preparation code

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 = {};

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 = {
  x: 1,
  y: 2,
  z: 3
Class instance
new Obj(1, 2, 3);

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment