array normal for loop vs for in

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    xs = []
    for (var i = 0; i < 1000000; i += 1) {
      xs.push(i);
    }
};
</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 loop
ys = []
for (var i = 0; i < xs.length; i += 1) {
  ys.push(i * 10);
}
pending…
for in loop
ys = []
for (var i in xs) {
  ys.push(i * 10);
}
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