optimize afterthought

Benchmark created on


Setup

num = 100;
end = num ** (1 / 2);
divisors = [1];
disvisorPairs = [];
pairCount = 0;
for (var i = 2; i <= end; i++) {
  if (num % i == 0) {
    divisors.push(i);
    pair = num / i;
    if (pair != i) {
      pairCount++;
      disvisorPairs.push(pair);
    }
  }
}

Test runner

Ready to run.

Testing in
TestOps/sec
decrement in afterthought
for (var i = pairCount - 1; i >= 0; i--) {
  divisors.push(disvisorPairs[i]);
}
ready
no afterthought
for (var i = pairCount; i--; ) {
  divisors.push(disvisorPairs[i]);
}
ready

Revisions

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