Test name | Executions per second |
---|---|
Splice | 172.1 Ops/sec |
Temp | 4299.3 Ops/sec |
var tests = 100,
ct = 100000,
arr = [];
for (var i = 0; i < ct; i++) {
arr[i] = Math.floor(Math.random() * ct) + 1;
}
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]);
}
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;
}