Declaring variables inside loops (v7)

Revision 7 of this benchmark created by Terry Anastasiadis on


Description

Tests whether declaring a variable inside a loop, rather than declaring outside and just assigning values, is more performant

Preparation HTML

<script>
  var LENGTH = 3;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Inside
var len_00 = LENGTH;
while (len_00-- > 0) {
  var len_01 = LENGTH,
      a = {},
      b = {},
      c = {},
      d = {},
      e = {},
      f = {};
  while (len_01-- > 0) {
    var len_02 = LENGTH,
        g = {},
        h = {},
        i = {},
        j = {},
        k = {},
        l = {};
    while (len_02-- > 0) {
      var len_03 = LENGTH,
          m = {},
          n = {},
          o = {},
          p = {},
          q = {},
          r = {};
      while (len_03-- > 0) {
        var s = {},
            t = {},
            u = {},
            v = {},
            w = {},
            x = {},
            y = {},
            z = {};
      }
    }
  }
}
ready
Outside
var len_00 = LENGTH,
    len_01, len_02, len_03, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
while (len_00-- > 0) {
  len_01 = LENGTH;
  a = {};
  b = {};
  c = {};
  d = {};
  e = {};
  f = {};
  while (len_01-- > 0) {
    len_02 = LENGTH;
    g = {};
    h = {};
    i = {};
    j = {};
    k = {};
    l = {};
    while (len_02-- > 0) {
      len_03 = LENGTH;
      m = {};
      n = {};
      o = {};
      p = {};
      q = {};
      r = {};
      while (len_03-- > 0) {
        s = {};
        t = {};
        u = {};
        v = {};
        w = {};
        x = {};
        y = {};
        z = {};
      }
    }
  }
}
ready

Revisions

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