delete key vs destructure (v2)

Revision 2 of this benchmark created on


Setup

const items = Array.from(Array(10000).keys());

const BIG_DATA_SET = items.reduce(
  (o, key) => ({
    ...o,
    [`${key}`]: {
      request: {
        id: `${key}`,
        nested: {
          request: {
            id: `${key}`,
          },
        },
      },
    },
  }),
  {}
);

const target = "5123";
const prevData = { data: BIG_DATA_SET };

console.log(Object.keys(BIG_DATA_SET).length);

Test runner

Ready to run.

Testing in
TestOps/sec
destructure
const { [target]: {}, ...rest } = prevData.data
return { data: rest };
ready
delete
delete prevData.data[target];
return { data: prevData.data };
ready
object.assign
const obj = Object.assign({}, prevData)
delete obj.data[target]
return obj
ready
object keys
const newData = Object.keys(prevData.data).reduce((object, key) => {
  if (key !== target) {
    object[key] = prevData.data[key];
  }
  return object;
}, {});
return newData

ready

Revisions

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