Obejct.keys vs map

Benchmark created on


Setup

var list = Array(1000).fill().map(() => ({id: Math.floor(Math.random() * 100000)}))

var obj = list.reduce((acc, curr) => ({
    ...acc,
    [curr.id]: curr
}),{})

Test runner

Ready to run.

Testing in
TestOps/sec
Extract ids from list with map
var fromList = list.map((item) => item.id)
ready
Extract from object with Object.Keys
var fromObj = Object.keys(obj)
ready

Revisions

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