Assign Object Maciej Cieslar

Benchmark created by maciejcieslar on


Setup

const obj1 = {
    prop1: true,
    prop2: true,
    prop3: true,
  }
  
  const obj2 = {
    prop2: false,
    prop4: false,
  }
  
  
  const assign1 = (target, ...sources) => {
    sources.forEach((source) => {
      return Object.keys(source).forEach((key) => {
        target[key] = source[key]
      })
    })
  
    return target
  }
  
  const assign2 = (...sources) => {
    return sources.reduce((result, current) => {
      return {
        ...result,
        ...current,
      }
    }, {})
  }

Test runner

Ready to run.

Testing in
TestOps/sec
v1
assign1(obj1, obj2)
ready
v2
assign2(obj1, obj2)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by maciejcieslar on