тесты
var arrA = [...Array(1000000).keys()];
var arrB = [...Array(1000000).keys()];
var arrC = [...Array(1000000).keys()];
var resA = [];
var resB = [];
var resC = [];
function testSplice(){
return arrA.splice(0, 1);
}
function testSpliceEnd(){
return arrB.splice(arrB.length - 1);
}
function testSpliceX(){
var arr = arrC.slice(arrC.length - 1);
arrC.length -= 1;
return arr;
}
console.time('splice');
for (var i=0; i < 50000; i++){
resA.push(testSplice());
}
console.timeEnd('splice');
console.time('spliceEnd');
for (var i=0; i < 50000; i++){
resB.push(testSpliceEnd());
}
console.timeEnd('spliceEnd');
console.time('spliceX');
for (var i=0; i < 50000; i++){
resC.push(testSpliceX());
}
console.timeEnd('spliceX');
console.log(arrA.length, arrB.length, arrC.length);