Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.assign vs spread operator 2
(version: 0)
Comparing performance of:
Object.assign vs spread operator
Created:
7 years ago
by:
Guest
Jump to the latest result
Tests:
Object.assign
var params = { b:"hello", c: true, d:7 }; var other = Object.assign({ a: 2 }, params);
spread operator
var params = { b:"hello", c: true, d:7 }; var other = { a: 2, ...params };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.assign
spread operator
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**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: 1. `Object.assign()` 2. The spread operator (`...`) **Pros and Cons of each approach** 1. **`Object.assign()`** * Pros: + Widely supported in older browsers (IE 9+) + Simple to use * Cons: + Performance is generally slower compared to the spread operator 2. **The spread operator (`...`)** * Pros: + Faster performance compared to `Object.assign()` + More modern and widely supported in modern browsers (IE 11+, Chrome 44+, Firefox 35+, Edge 14+) * Cons: + Introduced in ECMAScript 2018, so not compatible with older JavaScript versions + May require a more recent browser or transpiler to work **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: * Using `concat()` to concatenate two arrays * Using a library like Lodash's `merge` function * Using a simple loop to iterate over properties and assign values However, 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.
Related benchmarks:
Spread vs Object.assign (modify ) vs Object.assign (new)
object.assign vs spread to create a copy
JavaScript spread operator vs Object.assign performance without useless assignment
JavaScript spread operator vs Object.assign performance - Kien Nguyen
Object.assign() vs spread operator (New object)
Comments
Confirm delete:
Do you really want to delete benchmark?