Loops and values access (v157)

Revision 157 of this benchmark created on


Description

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

Preparation HTML

<script>
  var arr = new Array(100);
</script>

Test runner

Ready to run.

Testing in
TestOps/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];
};
ready
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;
};
ready
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];
};
ready
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;
};
ready

Revisions

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