for loop with with array length cached vs for loop that reads array length every time

Edit on GitHub

Setup

Tests

  • for loop with with array length cached

    var a = new Array(100).fill(1)
    var len = a.length
    var b = []
    for (var i = 0; i < len; i++) {
      b.push(i)
    }
  • for loop that reads array length every time

    var a = new Array(100).fill(1)
    var len = a.length
    var b = []
    for (var i = 0; i < len; i++) {
      b.push(i)
    }