for-array-tests

JavaScript performance comparison

Test case created by yzsolt

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
   
    var test_array = new Array(10000);
    for (var i = 0; i < test_array.length; i++) {
        test_array[i] = Math.random();
    }
};
</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
Simplest
var test;

for (var i = 0; i < test_array.length; i++) {
    test = test_array[i];
}
pending…
Outer length precalc
var test;
var length = test_array.length;

for (var i = 0; i < length; i++) {
    test = test_array[i];
}
pending…
Inner length precalc
var test;

for (var i = 0, length = test_array.length; i < length; i++) {
    test = test_array[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