Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Chrome 120
Windows
Desktop
one year ago
Test name Executions per second
reduce 3250.4 Ops/sec
map + fromEntries 1361.4 Ops/sec
for loop 3337.8 Ops/sec
Script Preparation code:
AخA
 
var data = Array.from(Array(10000).keys());
Tests:
  • reduce

     
    Object.entries(data).reduce((acc, [k, v]) => {
      acc[k] = v.toString();
      return acc;
    }, {});
  • map + fromEntries

     
    Object.fromEntries(Object.entries(data).map(([k, v]) => ([k, v.toString()])));
  • for loop

     
    const dataObject = Object.entries(data)
    const acc = {}
    for (let i = 0; i < dataObject.length; i++) {
      const [k, v] = dataObject[i];
      acc[k] = v.toString()
    }