es6-spread-operator-vs-foreach-performance

Benchmark created on


Setup

const stores = Array(10000).fill({
    "id": 1,
    "code": "code",
    "banner": "banner",
    "banner_sub": "banner_sub",
    "city": "city",
    "surface": 1000,
    "surface_group": "surface_group",
    "franchised": false,
    "region_id": 99999999,
    "region": "region",
    "region_key": "region_key",
    "open": false,
    "opened_at_formatted": null,
    "closed_at_formatted": null
})
let storeCSVHeader = [];

Test runner

Ready to run.

Testing in
TestOps/sec
foreach
stores.forEach((store) =>
               storeCSVHeader.push([
                    store.code,
                    store.banner,
                    store.city,
                    store.region,
                    `${store.surface}`,
                  ])
                );
ready
spread
storeCSVHeader.push(
                  ...stores.map((store) => [
                    store.code,
                    store.banner,
                    store.city,
                    store.region,
                    `${store.surface}`,
                  ])
                );
ready

Revisions

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