Assign Object Maciej Cieslar

JavaScript performance comparison

Test case created by maciejcieslar

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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,
      }
    }, {})
  }
  
  

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
v1
assign1(obj1, obj2)
pending…
v2
assign2(obj1, obj2)
pending…

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

Compare results of other browsers

0 Comments