inherit-Object-vs-Array (v3)

Revision 3 of this benchmark created by kazuho on


Setup

function Point(x, y) {
      this.x = x;
      this.y = y;
    }
    
    Point.prototype = new Object();
    
    function Point2(x, y) {
      this[0] = x;
      this[1] = y;
    }
    
    Point2.prototype = new Array();
    
    function PointArray(x, y) {
      return [x, y];
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Object
(function(n, p) {
  var ret = 0;
  for (var i = 0; i < 1000; ++i) {
    for (var j = 0; j < n; ++j) {
      if (p.x % j) {
        ret += p.y;
      }
    }
  }
  return ret;
})(100, new Point(10, 10));
ready
Array-inherited
(function(n, p) {
  var ret = 0;
  for (var i = 0; i < 1000; ++i) {
    for (var j = 0; j < n; ++j) {
      if (p[0] % j) {
        ret += p[1];
      }
    }
  }
  return ret;
})(100, new Point2(10, 10));
ready
Array-not-inherited
(function(n, p) {
  var ret = 0;
  for (var i = 0; i < 1000; ++i) {
    for (var j = 0; j < n; ++j) {
      if (p[0] % j) {
        ret += p[1];
      }
    }
  }
  return ret;
})(100, PointArray(10, 10));
ready

Revisions

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