Run details:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Firefox 87
Ubuntu
Desktop
4 years ago
Test name Executions per second
boring 46994048.0 Ops/sec
spread 6300799.5 Ops/sec
Object.assign 9192079.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"
    });