Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.assign vs spread operator large objects
(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, e: 'e', f: 'f', g: 'g', h: 'h', i: 1, j: 2, k: 3, l: 7, m: 7, n: 3, o: 'o', p: "azazazazazazazazaz", q: 'qqqqqqq' }; var other = Object.assign({ a: 2, aa: 2, aaa: 3, aaaa: 'aaaa' }, params);
spread operator
var params = { b:"hello", c: true, d:7, e: 'e', f: 'f', g: 'g', h: 'h', i: 1, j: 2, k: 3, l: 7, m: 7, n: 3, o: 'o', p: "azazazazazazazazaz", q: 'qqqqqqq' }; var other = { a: 2, aa: 2, aaa: 3, aaaa: 'aaaa', ...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):
**Overview of the Benchmark** The provided benchmark measures the performance difference between using `Object.assign()` and the spread operator (`...`) when assigning large objects to a new variable in JavaScript. **Benchmark Definition JSON** The benchmark definition json contains two test cases: 1. "Object.assign" 2. "spread operator" Each test case has a unique script preparation code that defines a large object `params` with various properties, including strings, numbers, booleans, and other data types. 3. The first test case uses the `Object.assign()` method to assign the `params` object to another object `other`. 4. The second test case uses the spread operator (`...`) to create a new object by spreading the `params` object's properties. **Options Compared** The benchmark compares two options: 1. **Object.assign()**: A widely used method for assigning objects in JavaScript. 2. **Spread Operator (`...`)**: A newer, more concise way of creating objects by spreading existing objects' properties. **Pros and Cons of Each Approach** **Object.assign():** Pros: * Wide support across browsers and versions * Can handle nested objects and arrays Cons: * Can be slower due to the overhead of function calls * May not work as expected when dealing with non-object values (e.g., numbers, strings) **Spread Operator (`...`):** Pros: * Faster execution time compared to `Object.assign()` * More concise and readable code * Works well with non-object values Cons: * Not supported in older browsers or versions * May not work as expected when dealing with complex object structures **Library Used: None** There are no libraries used in this benchmark. **Special JS Feature/Syntax: None** This benchmark does not use any special JavaScript features or syntax, such as async/await, ES6 classes, or generators. **Other Alternatives** If you need to compare the performance of other assignment methods, consider these alternatives: * **Destructuring Assignment**: Similar to the spread operator, but for objects instead of arrays. * **Array.prototype.slice() or Array.prototype.concat()**: For assigning entire arrays instead of objects. Keep in mind that these alternatives might not be as suitable for this specific benchmark, which focuses on object assignment.
Related benchmarks:
object assign vs object spread on growing objects
JavaScript spread operator vs Object.assign performance without mutating original object
JavaScript spread operator vs Object.assign performance - Kien Nguyen
Object.assign() vs spread operator (New object)
JavaScript spread operator vs Object.assign performance without overwriting original object
Comments
Confirm delete:
Do you really want to delete benchmark?