Mapping collection keys

Benchmark created on


Setup

const id = 'some-long-title'
const arr = new Array(50000).fill({
  "some-long-title.keyOne": 100,
  "some-long-title.keyTwo": 200,
  "some-long-title.keyThree": 300,
  "some-long-title.keyFour": 400
})

Test runner

Ready to run.

Testing in
TestOps/sec
Map collection keys with `String.prototype.substring()`
arr.map((value) =>
  Object.fromEntries(
    Object.keys(value).map((key) => [key.substring(id.length + 1), value[key]])
  )
)
ready
Map collection keys with `String.prototype.replace()`
arr.map((value) =>
  Object.fromEntries(
    Object.keys(value).map((key) => [key.replace(`${id}.`, ""), value[key]])
  )
)
ready

Revisions

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