Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JavaScript spread operator vs Object.assign performance 11
(version: 0)
Comparing performance of:
Using the spread operator vs Using Object.assign
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
Using the spread operator
const firstObject = { sampleData: 'Hello world' } const secondObject = { moreData: 'foo bar' } const finalObject = { ...firstObject, ...secondObject };
Using Object.assign
const firstObject = { sampleData: 'Hello world' } const secondObject = { moreData: 'foo bar' } const finalObject = Object.assign(firstObject, secondObject, {});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Using the spread operator
Using Object.assign
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):
Let's break down what's being tested on the provided JSON benchmark. **Benchmark Definition** The benchmark is defined by the script preparation code, which consists of two examples: 1. Using the spread operator (`...`): This syntax was introduced in ECMAScript 2018 (ES2018) and allows you to expand an object into a new object. 2. Using `Object.assign()`: This method is used to copy properties from one or more source objects to a target object. **Options being compared** The two options are: * Using the spread operator (`...`) * Using `Object.assign()` These options are being compared in terms of performance, specifically in terms of how many executions per second they can achieve on a Chrome 116 browser on a Windows desktop platform. **Pros and Cons of each approach** 1. **Using the spread operator (`...`)**: * Pros: + More concise and readable syntax + Easier to use when dealing with simple objects * Cons: + May be slower due to method call overhead (in JavaScript, methods are functions that can be invoked on an object) 2. **Using `Object.assign()`**: * Pros: + Faster than the spread operator because it avoids method call overhead + More efficient for large objects or complex data structures * Cons: + Less readable syntax compared to the spread operator **Library and purpose** The only library mentioned in the benchmark is `Object.assign()`, which is a built-in method in JavaScript that allows you to copy properties from one or more source objects to a target object. **Special JS feature or syntax** None of the test cases use any special JavaScript features or syntax beyond what's mentioned above (ECMAScript 2018 and `Object.assign()`). **Other alternatives** There are other ways to merge objects in JavaScript, such as: * Using the `merge` function from a library like Lodash * Using a custom implementation of object merging * Using template literals (`{ ... }`) which was introduced in ECMAScript 2015 (ES6) and allows you to merge two objects into one However, these alternatives are not being compared in this benchmark. Keep in mind that performance differences between these options may vary depending on the specific use case, data size, and browser version.
Related benchmarks:
object assign vs object spread on growing objects
JavaScript spread operator vs Object.assign performance (single addition)
JavaScript spread operator vs Object.assign performance - Kien Nguyen
Object.assign() vs spread operator (New object)
JavaScript spread operator vs Object.assign performance test number 99
Comments
Confirm delete:
Do you really want to delete benchmark?