A spread copy is ~1.4× slower than `Object.assign`
Object.assign wins for shallow copies. The gap is 1.4× — a small price for the readability of spread.
Result
| Run | spread copy | `Object.assign(, obj)` | Ratio |
|---|---|---|---|
| Run 1 | 0.863 | 0.565 | 1.53× |
| Run 2 | 0.755 | 0.598 | 1.26× |
| Run 3 | 0.818 | 0.636 | 1.29× |
Conditions
200,000 shallow copies of a 10-key object.
Where this number does not apply
Unless you copy every frame inside a hot loop, this difference will not be perceptible.
Reproduce
cd bench
node --expose-gc micro-fixed.mjs --out ../data/run.json --samples 21 Run it three times on the same machine; if the spread of median stays under 10%, you should land on the same conclusion. If your numbers disagree, tell us and we will retract.