Hidden Classes vs Functions

JavaScript performance comparison

Test case created by GW

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function test(a, b, c, d) {
   return a + b + c + d;
  }
  
  function testOpts(opts) {
    return opts.a + opts.b + opts.c + opts.d;
  }
  
  function sepTestOpts(opts) {
    return opts.a + opts.b + opts.c + opts.d;
  }
  
  
  var count = 0;
  function genTest() {
    ++count;
    if (count % 2) {
      test(0,0,0,0);
    }
  
    if (count % 3) {
      test(0,0,0,1);
    }
  
    if (count % 4) {
      test(0,0,1,1);
    }
  
    if (count % 5) {
      test(0,1,1,1);
    }
  
    if (count % 6) {
      test(1,1,1,1);
    }
  }
  
  function genTestOpts() {
    ++count;
    if (count % 2) {
      testOpts({a:0,b:0,c:0,d:0});
    }
  
    if (count % 3) {
      testOpts({a:0,b:0,c:0,d:1});
    }
  
    if (count % 4) {
      testOpts({a:0,b:0,c:1,d:1});
    }
  
    if (count % 5) {
      testOpts({a:0,b:1,c:1,d:1});
    }
  
    if (count % 6) {
      testOpts({a:1,b:1,c:1,d:1});
    }
  }
  
  function genTestOptsShapeChange() {
    ++count;
    if (count % 2) {
      testOpts({a:0,b:0,c:0,d:0,e:1});
    }
  
    if (count % 3) {
      testOpts({a:0,b:0,c:0,d:1,f:2});
    }
  
    if (count % 4) {
      testOpts({a:0,b:0,c:1,d:1,g:3});
    }
  
    if (count % 5) {
      testOpts({a:0,b:1,c:1,d:1,h:4});
    }
  
    if (count % 6) {
      testOpts({a:1,b:1,c:1,d:1,i:5});
    }
  }
  
  
  function genTestOptsShapeChangeSepFun() {
    ++count;
    if (count % 2) {
      sepTestOpts({a:0,b:0,c:0,d:0,e:1});
    }
  
    if (count % 3) {
      sepTestOpts({a:0,b:0,c:0,d:1,f:2});
    }
  
    if (count % 4) {
      sepTestOpts({a:0,b:0,c:1,d:1,g:3});
    }
  
    if (count % 5) {
      sepTestOpts({a:0,b:1,c:1,d:1,h:4});
    }
  
    if (count % 6) {
     sepTestOpts({a:1,b:1,c:1,d:1,i:5});
    }
  }

};
</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
Function
genTest()
pending…
Objects
genTestOpts()
pending…
Shape Changing Objects
genTestOptsShapeChange()
pending…
Shape Change Objects Separate Function
genTestOptsShapeChangeSepFun()
pending…

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

0 Comments