append ループ is ~1.11× slower than リスト内包表記
A list comprehension is ~11% faster than an append loop.
Result
| Run | append ループ | リスト内包表記 | Ratio |
|---|---|---|---|
| Run 1 | 19.181 | 17.292 | 1.11× |
| Run 2 | 18.617 | 16.908 | 1.10× |
| Run 3 | 19.264 | 17.464 | 1.10× |
Spread over 3 runs: append ループ CV 1.5% / リスト内包表記 CV 1.3% / Ratio CV 0.3%
Conditions
Building 300,000 elements.
Where this number does not apply
With complex per-item work, a comprehension stops being readable.
Reproduce
cd bench && python micro_py.py --out ../data/run.json --samples 21