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"
    });
  • Terinary

     
    const obj = {
      hello: "world"
    };
    Math.random()>.5 ? obj.foo = "bar" : false
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    boring
    spread
    Object.assign
    Terinary

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 OPR/107.0.0.0
Opera 107 on Windows
View result in a separate tab
Test name Executions per second
boring 9409034.0 Ops/sec
spread 6808347.5 Ops/sec
Object.assign 4095814.0 Ops/sec
Terinary 11231471.0 Ops/sec