object iteration

JavaScript performance comparison

Test case created by Fabian

Info

Which case is faster for iterating of an object with much keys.

Preparation code

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

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
for-with-hasOwnProperty
for(var x in obj) { 
        if(obj.hasOwnProperty(x)) {
       
        }
};
pending…
object-keys-forEach
Object.keys(obj).forEach(function(v) {
       
});
pending…
object-keys-for
var arr = Object.keys(obj);
for(var x = 0; x < arr.length; 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. Here’s a list of current revisions for this page:

0 comments

Add a comment