Only numbers that came out the same three times
We benchmarked 21 pure-Python cases on CPython 3.12.14. Every case was run three separate times; anything whose median moved more than 10% (coefficient of variation), whose slower side took under 1 ms, or whose gap was under 5% is not published.
What we publish
例外で分岐 is ~4.11× slower than in で判定4.11× · CV 1.7%json.dumps is ~2.62× slower than pickle.dumps2.62× · CV 3.2%deepcopy is ~37.04× slower than copy(浅い)37.04× · CV 0.9%% 書式 is ~1.75× slower than f-string1.75× · CV 3.2%正規表現 is ~2.33× slower than startswith2.33× · CV 3.5%index 参照 is ~1.54× slower than 直接イテレート1.54× · CV 1.2%sum(list(range(n))) is ~1.78× slower than sum(range(n))1.78× · CV 3.6%deepcopy is ~1.62× slower than JSON ラウンドトリップ1.62× · CV 0.9%dict.fromkeys is ~1.49× slower than set() で重複除去1.49× · CV 3.4%enumerate is ~1.45× slower than range(len())1.45× · CV 2.6%dict の参照 is ~1.12× slower than __slots__ 属性1.12× · CV 0.4%append ループ is ~1.11× slower than リスト内包表記1.11× · CV 0.3%sorted() で新リスト is ~1.06× slower than list.sort() インプレース1.06× · CV 3.5%What this answers — and what it does not
- Answers: for the same input size on CPython, which way of writing it is faster
- Does not answer: PyPy/JIT differences, memory use, parallelism, rankings at other input sizes
The method, the machine and the reproduction command live in Measurement protocol。