caching length (v85)

Revision 85 of this benchmark created by Steven on


Setup

var arr = [];
    for (var i = 0; i < 1000; i++) {
      arr[i] = Math.random();
    }

Test runner

Ready to run.

Testing in
TestOps/sec
cached
for (var i = 0, len = arr.length; i < len; i++) {
  arr[i] *= 2;
}
ready
not cached
for (var i = 0; i < arr.length; i++) {
  arr[i] *= 2;
}
ready
u wot m8
var len = 2;
len *= arr.length;
len -= len / 2;
for (var i = 0; i < len; i++) {
  arr[i] *= 2;
}
ready
while loop
var len = arr.length;
while (len--) {
  arr[len] *= 2;
}
ready
do-while loop
var len = arr.length;
do {
  arr[len] *= 2;
} while (len--);
ready
Prefix Increment
for (var i = 0; i < arr.length; ++i) {
  arr[i] *= 2;
}
ready
Prefix + Cached
for (var i = 0, len = arr.length; i < len; ++i) {
  arr[i] *= 2;
}
ready
Array map
arr.map(function(el) {
  return el * 2;
});
ready
Defined outside
var len = arr.length;
for (var i = 0; i < len; i++) {
  arr[i] *= 2;
}
ready

Revisions

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