Script Preparation code:
x
 
var IDLE = 0;
var CONSOLE_LOG = 1;
var CONSOLE_WARN = 2;
var CONSOLE_ERROR = 3;
var CONSOLE_INFO = 4;
var COMPLETE = 5;
var currentState = IDLE;
var string = 'Hello World!';
function functionSwitchLoop() {
    switch(currentState) {
      case IDLE:
        currentState = CONSOLE_LOG;
        return functionSwitchLoop();
      case CONSOLE_LOG:
        console.log(string);
        currentState = CONSOLE_WARN;
        return functionSwitchLoop();
      case CONSOLE_WARN:
        console.warn(string);
        currentState = CONSOLE_ERROR;
        return functionSwitchLoop();
      case CONSOLE_ERROR:
        console.error(string);
        currentState = CONSOLE_INFO;
        return functionSwitchLoop();
      case CONSOLE_INFO:
        console.info(string);
        return currentState = COMPLETE;
    };
};
Tests:
  • if loop

     
    if(currentState === IDLE) {
        currentState = CONSOLE_LOG;
    };
    if(currentState === CONSOLE_LOG) {
        console.log(string);
        currentState = CONSOLE_WARN;
    };
    if(currentState === CONSOLE_WARN) {
        console.warn(string);
        currentState = CONSOLE_ERROR;
    };
    if(currentState === CONSOLE_ERROR) {
        console.error(string);
        currentState = CONSOLE_INFO;
    };
    if(currentState === CONSOLE_INFO) {
        console.info(string);
        currentState = COMPLETE;
    };
    if(currentState === COMPLETE) currentState = IDLE;
  • while + switch/case loop

     
    while(currentState != COMPLETE) {
        switch(currentState) {
            case IDLE:
                currentState = CONSOLE_LOG;
                break;
            case CONSOLE_LOG:
                console.log(string);
                currentState = CONSOLE_WARN;
                break;
            case CONSOLE_WARN:
                console.warn(string);
                currentState = CONSOLE_ERROR;
                break;
            case CONSOLE_ERROR:
                console.error(string);
                currentState = CONSOLE_INFO;
                break;
            default:
                console.info(string);
                currentState = COMPLETE;
        };
    };
    currentState = IDLE;
  • function + switch/case loop

     
    functionSwitchLoop();
    currentState = IDLE;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    if loop
    while + switch/case loop
    function + switch/case loop

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0
Firefox 101 on Windows 7
View result in a separate tab
Test name Executions per second
if loop 9181.6 Ops/sec
while + switch/case loop 9104.1 Ops/sec
function + switch/case loop 8816.0 Ops/sec