js for in loop test

JavaScript performance comparison

Test case created by Bruce

Preparation code

<script>
var arr = new Array(1000 + 1).join('0').split('');

var foo = {
    "bar":{
        "method":{
            "add":function(n) {
                return ++n;
            }
        }
    }
};
</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 in loop
for(var i in arr) {
    arr[i] = foo.bar.method.add(arr[i]);
}
pending…
for in loop hasownproperty check
for(var i in arr) {
    if(arr.hasOwnProperty) {
        arr[i] = foo.bar.method.add(arr[i]);
    }
}
pending…
not local
for(i in arr) {
    arr[i] = foo.bar.method.add(arr[i]);
}
pending…
forEach
arr.forEach(function(e, i){
    arr[i] = foo.bar.method.add(arr[i]);
});
pending…

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

Compare results of other browsers

0 comments

Add a comment