Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Chrome 120
Linux
Desktop
one year ago
Test name Executions per second
fromEntries 816.2 Ops/sec
reducer 2097.2 Ops/sec
reducer with acc 0.1 Ops/sec
Script Preparation code:
AخA
 
vartest = test = Array(10000)
        .fill('')
        .map((_, i) => ({ key: 'key' + i, value: 'value' + i }));
Tests:
  • fromEntries

     
    const result = Object.fromEntries(test.map(({ key, value }) => [key, value]));
  • reducer

     
    const result2 = test.reduce((acc, { key, value }) => {
            acc[key] = value;
            return acc;
        }, {});
  • reducer with acc

     
    const result3 = test.reduce((acc, { key, value }) => ({...acc, [key]: value}), {});