object accesses (v7)

Revision 7 of this benchmark created on


Setup

var limit = 1000;
var arr = [];
var obj = [];
for (var i = 0; i < limit; i++){
	var a = Math.random();
	var b = {wah:"1223"};
	var c = "shit my ass";
	arr.push([a,b,c]);
	obj.push({a:a, b:b, c:c});
}

Test runner

Ready to run.

Testing in
TestOps/sec
timeout
var acc = 0;
var loops = 0;
function doloop1() {
	loops++;
	for (var i = 0; i < limit; i++){
		var idx = Math.floor(Math.random()*limit);
		var o = obj[idx];
		acc += o.a+o.b.wah.length + o.c.length;
	}
	if (loops < 10000) {
		setTimeout(doloop1, 0);
	}
}
doloop1();
ready
loop
var acc = 0;
var loops = 0;
function doloop2() {
	for (var j = 0; j < 10000; j++) {
		loops++;
		for (var i = 0; i < limit; i++){
			var idx = Math.floor(Math.random()*limit);
			var o = obj[idx];
			acc += o.a+o.b.wah.length + o.c.length;
		}
	}
}
doloop2();
ready

Revisions

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