446g465g34grtbvrt

JavaScript performance comparison

Test case created by artalar

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const state = {
    prop1: 1,
    prop2: 2,
    prop3: 3,
    prop4: 4,
    prop5: 5,
    prop6: 6
  };
  
  const propNames = Object.keys(state);
  
  const mergeClassic = (left, right) => {
    return { ...left, ...right };
  };
  
  const mergeSmart = (left, right) => {
    const newState = { ...left };
    for (const key in right) {
      if (right.hasOwnProperty(key)) {
        newState[key] = right[key];
      }
    }
    return newState;
  };

};
</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
mergeSmart
for (let i = 0; i < propNames.length; i++) {
  const propName = propNames[i]
  mergeSmart(state, { [propName]: state[propName] })
}
pending…
mergeClassic
for (let i = 0; i < propNames.length; i++) {
  const propName = propNames[i]
  mergeClassic(state, { [propName]: state[propName] })
}
pending…

Compare results of other browsers

Revisions

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

0 Comments