array vs obj vs unboxed

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function Point(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }
  var a_obj = new Point(1.23, 2.34, 3.45);
  var b_obj = new Point(4.56, 5.67, 6.78);
  var c_obj = new Point(0, 0, 0);
  var a_ary = [1.23, 2.34, 3.45];
  var b_ary = [4.56, 5.67, 6.78];
  var c_ary = [0, 0, 0];
  
  var a_x = 1.23;
  var a_y = 2.34;
  var a_z = 3.45;
  
  var b_x = 4.56;
  var b_y = 5.67;
  var b_z = 6.78;
  
  var c_x = 0;
  var c_y = 0;
  var c_z = 0;

};
</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
object adding
for (var i = 0; i < 500; ++i) {
  c_obj.x = a_obj.x + b_obj.x;
  c_obj.y = a_obj.y + b_obj.y;
  c_obj.z = a_obj.z + b_obj.z;
}


pending…
array adding
for (var i = 0; i < 500; ++i) {
  c_ary[0] = a_ary[0] + b_ary[0];
  c_ary[1] = a_ary[1] + b_ary[1];
  c_ary[2] = a_ary[2] + b_ary[2];
}
pending…
unboxed
for (var i = 0; i < 500; ++i) {
  c_x = a_x + b_x;
  c_y = a_y + b_y;
  c_z = a_z + b_z;
}
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