Tests:
  • for-loop + Map.set

    x
     
    const obj = {}
    const map = new Map()
    const n = 1000000;
    for (let i = 0; i < n; i++) {
      map.set(i, i);
    }
  • for-loop + Object assignment

     
    const obj = {}
    const map = new Map()
    const n = 1000000;
    for (let i = 0; i < n; i++) {
      obj[i] = i;
    }
  • forEach + Map.set

     
    const obj = {}
    const map = new Map()
    const n = Array(1000000).fill(0)
    n.forEach((value, index) => {
      map.set(index, index);
    })
  • forEach + Object assignment

     
    const obj = {}
    const map = new Map()
    const n = Array(1000000).fill(0)
    n.forEach((value, index) => {
      obj[index] = index;
    })
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    for-loop + Map.set
    for-loop + Object assignment
    forEach + Map.set
    forEach + Object assignment

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Chrome 97 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
for-loop + Map.set 9.4 Ops/sec
for-loop + Object assignment 43.4 Ops/sec
forEach + Map.set 5.4 Ops/sec
forEach + Object assignment 22.1 Ops/sec