array push vs length, to insert elements
Date tested:
2 years ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Test name
Executions per second
push
14225540.0 Ops/sec
length
14703440.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var arr = ['2', '2', '3', '2', '1', '[', '9', '8', '3', '0', 'p', 'g', 'r', 'p', 'u', 'h', ',', 'r', 'c', 'u', 'b', 'k', ']'];
Tests:
push
let a = []; for(let i = 0; i < arr.length; i ++){a[a.length] = arr.pop();}
length
let a = []; for(let i = 0; i < arr.length; i ++){a.push(arr.pop());}
Open this result on MeasureThat.net