for-array-tests (v2)

Revision 2 of this benchmark created by Uniquely Common on


Description

only the condition specified is the for block

Setup

var test_array = new Array(10000);
    for (var i = 0; i < test_array.length; i++) {
        test_array[i] = Math.random();
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Simplest
var test;

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

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

for (var i = 0, length = test_array.length; i < length; i++) {
    test = test_array[i];
}
ready
increment inside
var test;

for (var i = 0, length = test_array.length; i < length;)  {
    test = test_array[i++];
}
 
ready
setup outside, increment inside
var test;
var i = 0, length = test_array.length;
for (; i < length; )  {
    test = test_array[i++];
}
 
ready

Revisions

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

  • Revision 2: published by Uniquely Common on