Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.assign vs mutation assign
(version: 0)
Comparing performance of:
Mutation vs Object.assign
Created:
7 years ago
by:
Guest
Jump to the latest result
Tests:
Mutation
let ob = {a:1, b:2}; ob.c = 3;
Object.assign
let ob = {a:1, b:2}; ob = Object.assign(ob, {c:3})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Mutation
Object.assign
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Mutation
111781144.0 Ops/sec
Object.assign
5226937.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the JavaScript microbenchmark on MeasureThat.net. **Benchmark Description** The benchmark is designed to compare the performance of two ways to assign new properties to an object in JavaScript: 1. **Mutation Assign**: This method directly modifies the original object by assigning new values to its existing properties. 2. **Object.assign()**: This method creates a shallow copy of the original object and then assigns new values to it. **Options Compared** The benchmark compares the performance of these two approaches. The goal is to determine which one is faster, more efficient, or more suitable for different use cases. **Pros and Cons** * **Mutation Assign**: + Pros: Simple, straightforward approach that doesn't create a new object. + Cons: Can be slower due to the need to access and modify existing properties. May also cause issues with prototype chains and inheritance. * **Object.assign()**: + Pros: Creates a shallow copy of the original object, which can help avoid prototype chain collisions. Generally faster than mutation assign due to reduced property lookups. + Cons: Creates an additional object, which may increase memory usage. **Other Considerations** When deciding between these approaches, consider the following factors: * **Prototype Chain**: If you're working with objects that inherit from a common prototype, using Object.assign() can help avoid issues with prototype chain collisions. * **Memory Usage**: If memory efficiency is crucial, using Object.assign() may be a better choice due to its ability to create a shallow copy of the original object. * **Performance**: In general, Object.assign() is faster than mutation assign due to reduced property lookups. **Library and Special JS Feature** There is no specific library mentioned in this benchmark. However, it's worth noting that some libraries like Lodash or Ramda might have their own implementations of Object.assign() with different optimizations or features. **Special JS Feature** This benchmark doesn't use any special JavaScript features beyond the standard syntax for object literals and assignment.
Related benchmarks:
Spread vs Object.assign (modify ) vs Object.assign (new)
Object.assign mutation vs spread
Object.assign vs direct copy
Object.assign vs mutation
Comments
Confirm delete:
Do you really want to delete benchmark?