Script Preparation code:
x
 
const shuffleArray = array => {
    const arr = [...array];
    for (let i = arr.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        const temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    return arr;
}
var testArr = Array.from({
    length: 5000
}, () => Math.floor(Math.random() * 4000));
var scrambled = shuffleArray(testArr);
Tests:
  • Array.sort + Array.findIndex

     
    scrambled.sort((a,b) => testArr.findIndex(t => t === a) - testArr.findIndex(t => t === b));
  • Array.map + Array.find

     
    testArr.map((t) => scrambled.find(s => s === t));
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Array.sort + Array.findIndex
    Array.map + Array.find

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Array.sort + Array.findIndex 223.0 Ops/sec
Array.map + Array.find 303.0 Ops/sec