Spread vs Object.assign

JavaScript performance comparison

Test case created by alystair

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let json = {
  "_id": "58218fe9d10d2c54057e350c",
  	"index": 0,
  	"guid": "10b21452-a09e-4eba-b2cc-b1aaf431fe87",
  	"isActive": false,
  	"balance": "$3,176.46",
  	"picture": "http://placehold.it/32x32",
  	"age": 36,
  	"eyeColor": "brown"
  };

};
</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
Object.assign
function foo(str='String',params={}){
 const options = {
	"guid": "10b21452-a09e-4eba-b2cc-b1aaf431fe87",
	"isActive": false,
	"picture": "http://placehold.it/32x32",
	"age": 36
 };
 Object.assign(options,params);
}
foo('bar',json);
pending…
Spread operator
function foo(str='String',params={}){
 const options = {
	"guid": "10b21452-a09e-4eba-b2cc-b1aaf431fe87",
	"isActive": false,
	"picture": "http://placehold.it/32x32",
	"age": 36,
  ...params
 };
}
foo('bar',json);
pending…

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

0 Comments