Test reduce

Benchmark created on


Setup

function toPrefixedKeysReduce(obj, prefix) {
  return Object.entries(obj).reduce((acc, [key, value]) => ({...acc, [`${prefix}${key}`]: value}), {});
}

function toPrefixedKeysForLoop(obj, prefix) {
  const newObj = {};
  for (const [key, value] of Object.entries(obj)) {
    newObj[`${prefix}${key}`] = value;
  }
  return newObj;
}

Test runner

Ready to run.

Testing in
TestOps/sec
reduce
toPrefixedKeysReduce({1: {key: 'hello'}}, 'pref')

ready
reduce 2
toPrefixedKeysForLoop({1: {key: 'hello'}}, 'pref')

ready

Revisions

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