For vs While

Edit on GitHub

Setup

var count = 1000 * 1000;
var sum = 0;

Tests

  • For

    for (var index = 0; index < count; index++) {
      sum += index;
    }
  • While

    var index = count;
    while(index--) {
      sum += index;
    }