JSベンチ実測MEASURED, NOT RECALLED

    ↑↓ で選択、Enter で開く。Esc で閉じる。

    Home / Findings

    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

    Runspread copy`Object.assign(, obj)`Ratio
    Run 10.8630.5651.53×
    Run 20.7550.5981.26×
    Run 30.8180.6361.29×

    Median spread: spread copy CV 5.5% / `Object.assign(, obj)` CV 4.9% / Ratio CV 8.8% (computed from the 3 runs)

    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.