Case Inside Loop (v3)

Revision 3 of this benchmark created on


Description

Checking the performance of case statement inside while loop vs conventional structures.

Setup

var lcl, ct;
    var jump = 0x01;

Test runner

Ready to run.

Testing in
TestOps/sec
For Loop
lcl = 1;

for (ct = 0; ct < 1000; ct++) {
  lcl++;
}

for (ct = 0; ct < 1000; ct++) {
  lcl--;
}
ready
Case + Loop
var jump = 0x01;

while (jump) {
  switch (jump) {
  case 0x01:
    lcl = 1;
  case 0x02:
    if (lcl >= 1000) {
      jump = 0x03;
      break;
    }
    lcl++;
    jump = 0x02;
    break;
  case 0x03:
    if (lcl <= 0) {
      jump = 0x04;
      break;
    }
    lcl--;
    jump = 0x03;
    break;
  case 0x04:
  default:
    jump = undefined;
    break;
  }
}
ready
While Loop
lcl = 1;
while (lcl < 1000) {
  lcl++;
}
while (lcl > 0) {
  lcl--;
}
ready

Revisions

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