arr loop method test

JavaScript performance comparison

Test case created by Johnson Jiang

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var targetArr = [];
    for (var i = 0; i < 100; i++) {
      targetArr.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 in
var newarr = [];
for (var i in targetArr) {
  newarr[i] = targetArr[i];
}
pending…
for loop
var newarr = [];
for (var i = 0; i < targetArr.length; i++) {
  newarr[i] = targetArr[i];
}
pending…
while
var newarr = [],
    i = 0;
while (i < targetArr.length) {
  newarr[i] = targetArr[i];
  i++;
}
pending…
do while
var newarr = [],
    i = 0;
do {
  newarr[i] = targetArr[i];
  i++;
}
while (i < targetArr.length);
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