Test mapping over object (v2)

Revision 2 of this benchmark created on


Setup

const data = {
  a: [new Date(), undefined, new Date(), undefined],
  b: [new Date(), undefined, new Date(), undefined],
  c: [new Date(), undefined, new Date(), undefined],
  d: [new Date(), undefined, new Date(), undefined],
  e: [new Date(), undefined, new Date(), undefined],
  f: [new Date(), undefined, new Date(), undefined]
};

Teardown

delete data;

Test runner

Ready to run.

Testing in
TestOps/sec
Spread entries
JSON.stringify({
  ...Object.entries(data).map(([k, v]) => ({
    k: v.map((e) => (e === undefined ? e : e.toISOString()))
  }))
});
ready
Spread keys
JSON.stringify({
  ...Object.keys(data).map((k) => ({
    k: data[k].map((e) => (e === undefined ? e : e.toISOString()))
  }))
});
ready
fromEntries entries
JSON.stringify(
  Object.fromEntries(
    Object.entries(data).map(([k, v]) => [
      k,
      v.map((e) => (e === undefined ? e : e.toISOString()))
    ])
  )
);
ready
fromEntries keys
JSON.stringify(
  Object.fromEntries(
    Object.keys(data).map((k) => [
      k,
      data[k].map((e) => (e === undefined ? e : e.toISOString()))
    ])
  )
);
ready
Reduce entries
JSON.stringify(
  Object.entries(data).reduce(
    (acc, [k, v]) => {
      acc[k] = v.map((e) => (e === undefined ? e : e.toISOString()));
      return acc;
    },
    {}
  )
);
ready
Reduce keys
JSON.stringify(
  Object.keys(data).reduce(
    (acc, k) => {
      acc[k] = data[k].map((e) => (e === undefined ? e : e.toISOString()));
      return acc;
    },
    {}
  )
);
ready
forEach entries
const rv = {};
Object.entries(data).forEach(
  ([k, v]) => (rv[k] = v.map((e) => (e === undefined ? e : e.toISOString())))
);
JSON.stringify(rv);
ready
forEach keys
const rv = {};
Object.keys(data).forEach(
  (k) => (rv[k] = data[k].map((e) => (e === undefined ? e : e.toISOString())))
);
JSON.stringify(rv);
ready
forOf entries
const rv = {};
for (const [k, v] of Object.entries(data)) {
  rv[k] = v.map((e) => (e === undefined ? e : e.toISOString()));
}
JSON.stringify(rv);
ready
forOf keys
const rv = {};
for (const k of Object.keys(data)) {
  rv[k] = data[k].map((e) => (e === undefined ? e : e.toISOString()));
}
JSON.stringify(rv);
ready

Revisions

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