Loops and values access

JavaScript performance comparison

Revision 157 of this test case created

Info

This will check which is the fastest way to access an array value multiple times

Preparation code

<script>
  var arr = new Array(100);
</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
while loop that imitates a for loop , caching the length getting value by index access
var i = arr.length;
while (i--) {
  var strigTest = 'one: ' + arr[i] + ' two: ' + arr[i] + ' tree ' + arr[i];
  arr[i];
};
pending…
while loop that imitates a for loop , caching the length getting storing value in var
var i = arr.length;
while (i--) {
  var val = arr[i];
  var strigTest = 'one: ' + val + ' two: ' + val + ' tree ' + val;
  val;
};
pending…
for loop, caching the length getting value by index access
var length = arr.length;
for (var i = 0; i < length; i++) {
  var strigTest = 'one: ' + arr[i] + ' two: ' + arr[i] + ' tree ' + arr[i];
  arr[i];
};
pending…
for loop , caching the length getting storing value in var
var length = arr.length;
for (var i = 0; i < length; i++) {
  var val = arr[i];
  var strigTest = 'one: ' + val + ' two: ' + val + ' tree ' + val;
  val;
};
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