Script Preparation code:
x
 
var objLiteral = {
  0: function() {
    console.log('A');
  },
  1: function() {
    console.log('B');
  },
  2: function() {
    console.log('C');
  }
}
var arrayLiteral = [
  function() {
    console.log('A');
  },
  function() {
    console.log('B');
  },
  function() {
    console.log('C');
  }
];
function usingSwitch(c) {
  switch (c) {
    case 0: console.log('A'); break;
    case 1: console.log('B'); break;
    case 2: console.log('C'); break;
  }
}
Tests:
  • Switch

     
    usingSwitch(Math.floor(Math.random() * 3))
  • Object Literal

     
    objLiteral[Math.floor(Math.random() * 3)]();
  • Array Literal

     
    arrayLiteral[Math.floor(Math.random() * 3)]();
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Switch
    Object Literal
    Array Literal

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 months ago)
Mozilla/5.0 (X11; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0
Firefox 132 on Linux
View result in a separate tab
Test name Executions per second
Switch 51493.5 Ops/sec
Object Literal 111453.7 Ops/sec
Array Literal 103886.2 Ops/sec