var params = { b:"hello", c: true, d:7 };
var other = Object.assign({ a: 2 }, params);
var params = { b:"hello", c: true, d:7 };
var other = { a: 2, params };
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object.assign | |
spread operator |
Test name | Executions per second |
---|---|
Object.assign | 3228587.2 Ops/sec |
spread operator | 1796128.6 Ops/sec |
What is being tested?
MeasureThat.net is testing the performance of two approaches to merge objects in JavaScript: Object.assign()
and the spread operator (...
).
Options being compared
The benchmark is comparing the performance of:
Object.assign()
...
)Pros and Cons of each approach
Object.assign()
...
)Object.assign()
Library and its purpose
None are mentioned in the provided benchmark definition.
Special JS feature or syntax
The spread operator (...
) is a relatively new feature introduced in ECMAScript 2018. It allows object destructuring and merging.
Benchmark preparation code
The script preparation code is empty, which means that no specific setup or initialization code is required to run the benchmark.
Other alternatives
If you want to test other approaches to merge objects, some examples include:
concat()
to concatenate two arraysmerge
functionHowever, these alternatives are not mentioned in the provided benchmark definition.
Benchmark result
The latest benchmark result shows that the spread operator (...
) outperforms Object.assign()
in this specific test case.