Array Push vs Unshift

Benchmark published by System on

Description

Compare adding elements to the end vs beginning of an array.

Setup

const generateData = () => [];

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Array.push
const arr = generateData();
for(let i=0; i<1000; i++) arr.push(i);
ready
Array.unshift
const arr = generateData();
for(let i=0; i<1000; i++) arr.unshift(i);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

Revision 1
publishedby Systemon