let ob = {a:1, b:2};
ob.c = 3;
let ob = {a:1, b:2};
ob = Object.assign(ob, {c:3})
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Mutation | |
Object.assign |
Test name | Executions per second |
---|---|
Mutation | 111781144.0 Ops/sec |
Object.assign | 5226937.0 Ops/sec |
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:
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
Other Considerations
When deciding between these approaches, consider the following factors:
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.