.push vs .map Perforamnce

Benchmark created on


Setup

const user = { id: 1 };
const offers = new Array(10000).fill({ id: Math.random(), status: 'pending' })

Test runner

Ready to run.

Testing in
TestOps/sec
.push
    const statusHistories = [];
    offers.forEach((offer) => {
      statusHistories.push({
        offerId: offer.id,
        status: offer.status,
        createdByUserId: user.id,
      });
    });
ready
.map
    const statusHistories = offers.map((offer) => ({
      offerId: offer.id,
      status: offer.status,
      createdByUserId: user.id,
    }));
ready

Revisions

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