JSベンチ実測MEASURED, NOT RECALLED

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

    Home / Findings

    `toFixed` is ~1.6× slower than `Intl.NumberFormat`

    With a cached instance, Intl.NumberFormat beats toFixed. If you need locale-aware grouping, you do not have to pay a speed penalty.

    Result

    Run`Number.toFixed(2)``Intl.NumberFormat` (2 decimals, cached)Ratio
    Run 119.98513.2411.51×
    Run 224.67814.3821.72×
    Run 322.53613.9601.61×

    Median spread: `Number.toFixed(2)` CV 8.6% / `Intl.NumberFormat` (2 decimals, cached) CV 3.4% / Ratio CV 5.2% (computed from the 3 runs)

    Conditions

    1,000,000 decimal formats (the Intl instance is built once, outside the loop).

    Where this number does not apply

    Building the Intl instance per call flips the result. If you need no grouping or currency symbol, toFixed is fine.

    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.