Script Preparation code:
x
 
arr = new Array(100).fill(null).map((_, i) => new Array(100).fill(null).map((_, j) => i + "," + j));
objA = {};
objB = {};
objs = [objA, objB];
randomValues = new Array(10000).fill(null).map(() => [Math.floor(Math.random()*100), Math.floor(Math.random()*100), objs[Math.floor(Math.random()*2)]]);
function getValue(obj, a , b) {
  if(obj === objA)
    return arr[a][b];
  else
    return arr[b][a];
}
Tests:
  • Normal access

     
    const [a, b] = randomValues[Math.floor(Math.random()*10000)];
    arr[a][b];
  • Conditional index-swapped access

     
    const [a, b, obj] = randomValues[Math.floor(Math.random()*10000)];
    getValue(obj, a, b);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Normal access
    Conditional index-swapped access

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.229 Whale/2.10.123.42 Safari/537.36
Chrome 90 on Windows
View result in a separate tab
Test name Executions per second
Normal access 2431450.8 Ops/sec
Conditional index-swapped access 1713081.9 Ops/sec