Loops (v97)

Revision 97 of this benchmark created by BrunoLM on


Setup

var a = new Array(100000);
    var len = a.length;
    var fn = function(i){ if (i<0 || i>=len) throw arguments.callee.caller; };
    
    for(var i=-1;++i<len;) a[i]=i;

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
for (var i = 0, n = a.length; i < n; ++i)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
ready
for reverse loop
for (var i = a.length - 1; i >= 0; --i)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
ready
for inc inline
for(var i = -1, n = a.length; ++i < n;)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
ready
for reverse dec inline
for (var i = a.length; --i >= 0;)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
ready
while reverse
var i = a.length - 1;
while (i >= 0)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
    --i;
}
ready
while reverse dec inline
var i = a.length;
while(i-- > 0)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
ready
while reverse dec inline implicit
var i = a.length;
while(i--)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
ready

Revisions

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