Tests:
  • Destructuring

    x
     
    let myArray = [12, -2, 55, 68, 80, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    const swapElementsDest = (array, index1, index2) => {
        [myArray[index1], myArray[index2]] = [myArray[index2], myArray[index1]];
    };
    for(let i = 0; i < myArray.length - 1; ++i){
        swapElementsDest(myArray, i, i+1)
    }
  • Temporary Variable

     
    let myArray = [12, -2, 55, 68, 80, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    const swapElementsTemp = (array, index1, index2) => {
        let temp = array[index1];
        array[index1] = array[index2];
        array[index2] = temp;
    };
    for(let i = 0; i < myArray.length - 1; ++i){
        swapElementsTemp(myArray, i, i+1)
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Destructuring
    Temporary Variable

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Chrome 118 on Windows
View result in a separate tab
Test name Executions per second
Destructuring 21399104.0 Ops/sec
Temporary Variable 40582708.0 Ops/sec