object spread vs polyfill

JavaScript performance comparison

Test case created by determin1st

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = {one:1, two:2, three:3, four:4, five:5, six:6, seven:7};
  
  var b;
  
  function import$(obj, src){
    var own = {}.hasOwnProperty;
    for (var key in src) if (own.call(src, key)) obj[key] = src[key];
    return obj;
  }
  
  function import$$(obj, src) {
    for (var key in src) {
      if (obj.hasOwnProperty(key)) {
        obj[key] = src[key];
      }
    }
    return obj;
  }
  
  function import$$$(obj, src) {
    for (var key in src) {
      if (Object.hasOwnProperty.call(obj, key)) {
        obj[key] = src[key];
      }
    }
    return obj;
  }

};
</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
native spread
b = {...a};
pending…
polyfill
b = import$({}, a);
pending…
Object.assign
b = Object.assign({}, a);
pending…
polyfill 2
b = import$$({}, a);
pending…
polyfill 3
b = import$$$({}, a);
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