Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 OPR/70.0.3728.106
Opera 70
Windows
Desktop
4 years ago
Test name Executions per second
Cache length 6521.2 Ops/sec
Do not cache 3281.3 Ops/sec
Script Preparation code:
AخA
 
var arr = [];
var count = 1000;
for(var i = 0; i<count; i++)
{
  arr.push(i);
}
Tests:
  • Cache length

     
    var arrLen = arr.length;
    var sum = 0;
    for (var i = 0; i < arrLen; i++){
      sum = arr[i];
    }
  • Do not cache

     
    var sum = 0;
    for (var i = 0; i < arr.length; i++){
      sum = arr[i];
    }