read-write array vs variable

JavaScript performance comparison

Test case created by Timo

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var pre_filled_array = [];
    for(var i=0;i<10;i++)
    {
      pre_filled_array.push(i);
    }
    var temp = 0;
};
</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
Array member directly
for(var i=0;i<10;i++)
{
  pre_filled_array[i] = pre_filled_array[i]+1;
  pre_filled_array[i] = pre_filled_array[i]*2;
  pre_filled_array[i] = pre_filled_array[i]/3;
  pre_filled_array[i] = pre_filled_array[i]-1;
  pre_filled_array[i] = pre_filled_array[i]+5;
  pre_filled_array[i] = pre_filled_array[i]*4;
  pre_filled_array[i] = pre_filled_array[i]/3;
  pre_filled_array[i] = pre_filled_array[i]-2;

}
pending…
Through temp var
for(var i=0;i<10;i++)
{
  temp = pre_filled_array[i];
  temp = temp+1;
  temp = temp*2;
  temp = temp/3;
  temp = temp-1;
  temp = temp+5;
  temp = temp*4;
  temp = temp/3;
  temp = temp-2;
  pre_filled_array[i]=temp;
}
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