Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
Chrome 89
Linux
Desktop
4 years ago
Test name Executions per second
boring 5686386.0 Ops/sec
spread 5028301.0 Ops/sec
Object.assign 2770951.0 Ops/sec
Tests:
  • boring

    AخA
     
    const obj = {
      hello: "world"
    };
    if (Math.random()>.5) {
      obj.foo = "bar";
    }
  • spread

     
    const obj = {
      hello: "world",
      ...Math.random()>.5 && { foo: "bar" }
    };
  • Object.assign

     
    const obj = Object.assign({
      hello: "world"
    }, Math.random()>.5 && {
      foo: "bar"
    });