Tests:
  • Object

    x
     
    const someOp = () => {
        console.info('boi')
    }
    const ops = {
      0: someOp,
      1: () => null,
      2: () => null,
      3: someOp,
    }
    for (let i = 0; i < 4; i++) {
      ops[i]();
    }
  • If statement

     
    const someOp = () => {
        console.info('boi')
    }
    const enter = 0;
    const exit = 3;
    for (let i = 0; i < 4; i++) {
     if (i === enter) {
       someOp();
     } else if (i === exit) {
       someOp();
     }
    }
  • Object (optional chain)

     
    const someOp = () => {
        console.info('boi')
    }
    const ops = {
      0: {
        func: someOp,
      },
      3: {
        func: someOp,
      }
    }
    for (let i = 0; i < 4; i++) {
      ops[i]?.func();
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Object
    If statement
    Object (optional chain)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
Chrome 84 on Mac OS X 10.14.6
View result in a separate tab
Test name Executions per second
Object 18652.3 Ops/sec
If statement 16721.7 Ops/sec
Object (optional chain) 18261.7 Ops/sec