sorted() で新リスト is ~1.06× slower than list.sort() インプレース
In-place `list.sort()` is ~6% faster than `sorted()` — the copy costs the difference.
Result
| Run | sorted() で新リスト | list.sort() インプレース | Ratio |
|---|---|---|---|
| Run 1 | 24.100 | 23.066 | 1.04× |
| Run 2 | 25.307 | 22.668 | 1.12× |
| Run 3 | 23.330 | 22.603 | 1.03× |
Spread over 3 runs: sorted() で新リスト CV 3.4% / list.sort() インプレース CV 0.9% / Ratio CV 3.5%
Conditions
Sorting 200,000 integers.
Where this number does not apply
If you need the original order, sorted() is required — 6% is not worth the loss.
Reproduce
cd bench && python micro_py.py --out ../data/run.json --samples 21