Script Preparation code:
AخA
 
var firstObject = {
    sampleData: 'Hello world'
}
var secondObject = {
    moreData: 'foo bar'
}
var merge = (def, opt) => {
    if (!opt) return def
    for (const key in def) {
        if (!Object.prototype.hasOwnProperty.call(opt, key) || opt[key] === undefined)
            opt[key] = def[key]
        else if (opt[key] === Object(opt[key]))
            opt[key] = merge(def[key], opt[key])
    }
    return opt
}
Tests:
  • Using the spread operator

     
    const finalObject = {
        ...firstObject,
        ...secondObject
    }
  • Using Object.assign

     
    const finalObject = Object.assign(firstObject, secondObject)
  • Using custom merge method (Create a clone object)

     
    const finalObject = merge(firstObject, secondObject)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Using the spread operator
    Using Object.assign
    Using custom merge method (Create a clone object)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Chrome 121 on Linux
View result in a separate tab
Test name Executions per second
Using the spread operator 8640652.0 Ops/sec
Using Object.assign 5470456.0 Ops/sec
Using custom merge method (Create a clone object) 1495925.0 Ops/sec