Immediately exiting while vs Not running while

Edit on GitHub

Checks whether an immediately canceling while loop is faster than a while loop that doesn’t run at all.

Setup

var x = 0;

Tests

  • Immediately exiting while

    while (x--) {}
  • Not running while

    if (x > 0) {
      while (x--) {}
    }