V8 Class Optimizations

JavaScript performance comparison

Test case created by mgibsonbr

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function DefaultProto(value) { this.value = value; }
  DefaultProto.prototype.foo = function(x) { return this.value * x; }
  
  function LiteralProto(value) { this.value = value; }
  LiteralProto.prototype = { foo:function(x) { return this.value * x; } }
  
  function ObjectProto(value) { this.value = value; }
  ObjectProto.prototype = new Object();
  ObjectProto.prototype.foo = function(x) { return this.value * x; }
  
  function ClassProto(value) { this.value = value }
  function ClassProtoProto() { 
      this.foo = function(x) { return this.value * x; };
  }
  ClassProto.prototype = new ClassProtoProto();
  
  var d = new DefaultProto(10);
  var l = new LiteralProto(10);
  var o = new ObjectProto(10);
  var c = new ClassProto(10);

};
</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
DefaultProto
d.foo(Math.random());
pending…
LiteralProto
l.foo(Math.random());
pending…
ObjectProto
o.foo(Math.random());
pending…
ClassProto
c.foo(Math.random());
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