% 書式 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-string | Ratio |
|---|---|---|---|
| Run 1 | 55.239 | 29.642 | 1.86× |
| Run 2 | 51.024 | 29.127 | 1.75× |
| Run 3 | 50.903 | 29.235 | 1.74× |
Spread over 3 runs: % 書式 CV 4.0% / f-string CV 0.8% / Ratio CV 3.2%
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