object iteration

JavaScript performance comparison

Revision 2 of this test case created by Arnor

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var obj = {};
   
  for(var i=0; i < 65536; i++) { 
  	obj[i] = "a"; 
  }
  
  var empty = [];

};
</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
for-with-hasOwnProperty
for(var x in obj) { 
	if(obj.hasOwnProperty(x)) {
	empty.push(x);
	}
}; 
pending…
object-keys-forEach
Object.keys(obj).forEach(function(v) {
		empty.push(v);

}); 
pending…
object-keys-for
var arr = Object.keys(obj);
for(var x = 0, l = arr.length; x < l; x++) {
	empty.push(x);
}
pending…
object-keys-for 2
var arr = Object.keys(obj);
for(var x = 0; x < arr.length; x++) {
	empty.push(x);
}
pending…

Compare results of other browsers

Revisions

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

0 Comments