map vs for-loop

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
map
const arr = [
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
]
const result = arr.map((item) => ({
  item,
}))
ready
for-loop
const arr = [
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
]
const result = []
for (let i = 0; i < arr.length; i++) {
  const item = arr[i]
  result.push({ item })
}
ready

Revisions

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