Tests:
  • Slice with spread

    x
     
    const a = ["a", "b", "d", "e"];
    const newItem = "c";
    const index = 2;
    const b = [...a.slice(0, index), newItem, ...a.slice(index)];
  • Slice using concat

     
    const a = ["a", "b", "d", "e"];
    const newItem = "c";
    const index = 2;
    const b = a.slice(0, index).concat(newItem, a.slice(index));
  • Splice

     
    const a = ["a", "b", "d", "e"];
    const newItem = "c";
    const index = 2;
    const b = [...a];
    b.splice(index, 0, newItem);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Slice with spread
    Slice using concat
    Splice

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36
Chrome 86 on Windows
View result in a separate tab
Test name Executions per second
Slice with spread 5409648.5 Ops/sec
Slice using concat 1681287.0 Ops/sec
Splice 7689725.5 Ops/sec