Pyベンチ実測MEASURED, NOT RECALLED

    ↑↓ to select, Enter to open, Esc to close

    % 書式 is ~1.75× slower than f-string

    Percent formatting beats f-strings by ~1.7× under this workload on CPython 3.12.

    Result

    Run% 書式f-stringRatio
    Run 155.23929.6421.86×
    Run 251.02429.1271.75×
    Run 350.90329.2351.74×

    Spread over 3 runs: % 書式 CV 4.0% / f-string CV 0.8% / Ratio CV 3.2%

    55.24 ms29.64 msRun151.02 ms29.13 msRun250.90 ms29.23 msRun3% 書式 (#b9c6d2) / f-string (#2f6f4f)

    Conditions

    Formatting two values 200,000 times.

    Where this number does not apply

    f-strings are more readable; the ranking may differ across CPython versions.

    Reproduce

    cd bench && python micro_py.py --out ../data/run.json --samples 21