Script Preparation code:
AخA
 
var arr = [
  { key: 'one',       val: 1 },
  { key: 'two',       val: 2 },
  { key: 'three',     val: 3 },
  { key: 'four',      val: 4 },
  { key: 'five',      val: 5 },
  { key: 'six',       val: 6 },
  { key: 'seven',     val: 7 },
  { key: 'eight',     val: 8 },
  { key: 'nine',      val: 9 },
  { key: 'ten',       val: 10 },
  { key: 'eleven',    val: 11 },
  { key: 'twelve',    val: 12 },
  { key: 'thirteen',  val: 13 },
  { key: 'fourteen',  val: 14 },
  { key: 'fifteen',   val: 15 },
  { key: 'sixteen',   val: 16 },
  { key: 'seventeen', val: 17 },
  { key: 'eighteen',  val: 18 },
  { key: 'nineteen',  val: 19 },
  { key: 'twenty',    val: 20 }
];
Tests:
  • Immutable reducer via spread operator

     
    const reducer = (obj, pair) => 
      ({...obj, [pair.key]: pair.val });
    arr.reduce(reducer, {});
  • Mutable reducer via property assign

     
    const reducer = (obj, pair) => {
      obj[pair.key] = pair.val;
      return Object.assign({}, obj);
    };
    arr.reduce(reducer, {});
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Immutable reducer via spread operator
    Mutable reducer via property assign

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 7 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Chrome 65 on Windows
View result in a separate tab
Test name Executions per second
Immutable reducer via spread operator 24450.1 Ops/sec
Mutable reducer via property assign 20241.0 Ops/sec