Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.assign vs spread operator
(version: 0)
Comparing performance of:
Object.assign vs spread operator vs jQuery extend vs Manual Update
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 };
jQuery extend
var params = { b:"hello", c: true, d:7 }; var other = $.extend({ a: 2 }, params);
Manual Update
var params = { b:"hello", c: true, d:7 }; params.a = 2; params.b = "NEW TEXT";
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Object.assign
spread operator
jQuery extend
Manual Update
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.assign
4463205.5 Ops/sec
spread operator
10108732.0 Ops/sec
jQuery extend
0.0 Ops/sec
Manual Update
86916600.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and other considerations. **Benchmark Overview** The benchmark compares the performance of four approaches to merge or update objects: 1. `Object.assign` 2. Spread operator (`{...params}`) 3. jQuery's `.extend()` method 4. Manual updates by directly modifying the object properties **What is being tested?** Each test case measures the execution time of a specific approach when performing one of the following operations: * Merging two objects (e.g., `Object.assign` or spread operator) * Updating an existing object's properties (e.g., "Manual Update") **Comparison Options and Pros/Cons:** 1. **Object.assign**: This method creates a new object with the target object as its prototype, then copies all enumerable own properties from the source object to the target object. * Pros: + Wide support across browsers + Simple and readable syntax * Cons: + Creates a new object, which can be memory-intensive for large datasets 2. **Spread operator (`{...params}`)**: This method creates a new object by spreading the properties of `params` onto an existing object. * Pros: + Efficient and concise syntax + No memory overhead, as it updates the existing object in-place * Cons: + Requires modern JavaScript version support (ES6+) 3. **jQuery extend**: This method creates a new object with merged properties from two sources. * Pros: + Familiar syntax for jQuery developers + Wide support across browsers that have jQuery * Cons: + jQuery is not required, which can add overhead due to loading and parsing the library 4. **Manual Update**: This approach updates an existing object's properties directly. * Pros: + No memory overhead, as no new objects are created * Cons: + Can be error-prone if not done carefully (e.g., losing original property values) **Library and Special JavaScript Features** The benchmark uses jQuery's `.extend()` method, which relies on the `$.extend` function. This function is a part of the jQuery library. No special JavaScript features are used in this benchmark beyond ES6 syntax support for the spread operator. **Benchmark Preparation Code and Results** The benchmark preparation code is empty for all test cases, indicating that the focus is solely on comparing the performance of each approach. The provided benchmark results show that: * The "Manual Update" approach has the highest execution time * The spread operator (`{...params}`) has a significantly lower execution time than `Object.assign` * jQuery's `.extend()` method returns 0 executions per second, indicating a potential issue or optimization problem Keep in mind that benchmark results can be influenced by various factors, such as: * JavaScript engine and browser performance * Object sizes and complexity * Memory constraints and allocation patterns These results should not be taken as absolute truth but rather as an approximation of performance characteristics under specific conditions.
Related benchmarks:
toFixed -> Number vs Math.round
toFixed() vs Math.round().toString()
toFixed() vs String(Math.floor()
toFixed vs Math.round() with numbers222
Instanceof VS toString for date comparison when using objects
Comments
Confirm delete:
Do you really want to delete benchmark?