JSベンチ実測MEASURED, NOT RECALLED

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

    Home / Findings

    `+=` is 3.6× faster than `push + join` for string building

    When you join 10,000 short strings, building with += beats collecting into an array and joining. V8's cons strings make repeated concatenation cheap.

    Result

    Runpush + join`+=` concatenationRatio
    Run 10.3000.0843.57×
    Run 20.3230.0903.58×
    Run 30.3080.0873.55×

    Median spread: push + join CV 3.1% / `+=` concatenation CV 2.9% / Ratio CV 0.3% (computed from the 3 runs)

    Conditions

    Joining 10,000 segments ('segment-0' … 'segment-9999') into one string.

    Where this number does not apply

    The gap shrinks for multi-megabyte strings or when you concatenate only a few times. Other browsers may behave differently.

    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.