index 参照 is ~1.54× slower than 直接イテレート
Iterating directly is ~1.5× faster than indexing with `range(len(xs))`.
Result
| Run | index 参照 | 直接イテレート | Ratio |
|---|---|---|---|
| Run 1 | 5.403 | 3.472 | 1.56× |
| Run 2 | 5.348 | 3.532 | 1.51× |
| Run 3 | 5.322 | 3.444 | 1.55× |
Spread over 3 runs: index 参照 CV 0.6% / 直接イテレート CV 1.1% / Ratio CV 1.2%
Conditions
Summing a 100,000-element list.
Where this number does not apply
If you need the index (neighbours, in-place writes), direct iteration is not an option.
Reproduce
cd bench && python micro_py.py --out ../data/run.json --samples 21