Loops

JavaScript performance comparison

Revision 102 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = new Array(100);
  var len = a.length;
  
  for(var i=-1;++i<len;) a[i]=i;
  var z = 99;

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
for loop
for (var i = 0, n = a.length; i < n; ++i)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
pending…
for reverse loop
for (var i = a.length - 1; i >= 0; --i)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
pending…
for inc inline
for(var i = -1, n = a.length; ++i < n;)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
pending…
for reverse dec inline
for (var i = a.length; --i >= 0;)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
pending…
while reverse
var i = a.length - 1;
while (i > -1)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
    --i;
}
pending…
while reverse dec inline
var i = a.length;
while(i-- > 0)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
pending…
while reverse dec inline implicit
var i = a.length;
while(i--)
{
    if (typeof(a[i]) === "undefined")
        throw "error";
}
pending…
total baseline
for(i;1;){
    if (typeof(a[i]) === "undefined")
        throw "error";
}
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.

0 Comments