Run details:
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
Chrome 53
Windows
Other
8 years ago
Test name Executions per second
Splice 172.1 Ops/sec
Temp 4299.3 Ops/sec
Script Preparation code:
AخA
 
var tests = 100,
    ct = 100000,
    arr = [];
for (var i = 0; i < ct; i++) {
  arr[i] = Math.floor(Math.random() * ct) + 1;
}
Tests:
  • Splice

     
    for (var i = tests; i--;) {
      var from = Math.floor(Math.random() * ct) + 1,
          to = Math.floor(Math.random() * ct) + 1,
          fromArr = arr.splice(from, 1);
      arr.splice(to, 0, fromArr[0]);
    }
  • Temp

     
    for (var i = tests; i--;) {
      var from = Math.floor(Math.random() * ct) + 1,
          to = Math.floor(Math.random() * ct) + 1,
          tmp = arr[from];
      arr[from] = arr[to];
      arr[to] = tmp;
    }