Pyベンチ実測MEASURED, NOT RECALLED

    ↑↓ to select, Enter to open, Esc to close

    sorted() で新リスト is ~1.06× slower than list.sort() インプレース

    In-place `list.sort()` is ~6% faster than `sorted()` — the copy costs the difference.

    Result

    Runsorted() で新リストlist.sort() インプレースRatio
    Run 124.10023.0661.04×
    Run 225.30722.6681.12×
    Run 323.33022.6031.03×

    Spread over 3 runs: sorted() で新リスト CV 3.4% / list.sort() インプレース CV 0.9% / Ratio CV 3.5%

    24.10 ms23.07 msRun125.31 ms22.67 msRun223.33 ms22.60 msRun3sorted() で新リスト (#b9c6d2) / list.sort() インプレース (#2f6f4f)

    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