for vs for in array

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var workload = {
        "workloadId": "68cf9344-5a3c-4e4a-927c-c1c9b6e48ccc",
        "elements": [
            {
                "name": "element1",
                "uri": "vm/hpcloud/nova/large"
            },
            {
                "name": "element2",
                "uri": "vm/hpcloud/nova/small"
            }
        ],
        "workloadStatus": "none"
    }
};
</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
var foo = workload.elements;
var len = foo.length;
for (var i = 0; i < len; i++) {
  console.log(foo[i])
}
pending…
for in
var foo = workload.elements;
for (var i in foo) {
  console.log(foo[i])
}
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