Array vs object tuple (v4)

Revision 4 of this benchmark created on


Setup

var objs = []
  var arrx = [];
  var arry = [];
  
      for(i = 0; i < 10000; i += 1) {
          var o = {x:Math.random(), y:Math.random()};
          objs[i] = o;
          arrx[i] = o.x;
          arry[i] = o.y;
      }

Test runner

Ready to run.

Testing in
TestOps/sec
Array
var compute_arr1 = function(arr) {
	var result=1;
	for(i = 0; i < arr.length; i++) {
		result = Math.sqrt(result) * Math.pow(arr[i]*10, 4);
	}
	return result;
};

	return compute_arr1(arrx) + compute_arr1(arry);
ready
Object
var compute_obj = function(arr) {
	var resultX=1;
	var resultY=1;
	for(i = 0; i < arr.length; i++) {
		resultX = Math.sqrt(resultX) * Math.pow(arr[i].x*10, 4);
		resultY = Math.sqrt(resultY) * Math.pow(arr[i].y*10, 4);
	}
	return resultX + resultY;
};

compute_obj(objs)
ready

Revisions

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