Pyベンチ実測MEASURED, NOT RECALLED

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

    sum(list(range(n))) is ~1.78× slower than sum(range(n))

    `sum(range(n))` is ~1.8× faster than `sum(list(range(n)))` — building the list costs the difference.

    Result

    Runsum(range(n))sum(list(range(n)))Ratio
    Run 117.00831.2150.54×
    Run 217.46530.6830.57×
    Run 318.55231.1570.60×

    Spread over 3 runs: sum(range(n)) CV 3.7% / sum(list(range(n))) CV 0.8% / Ratio CV 3.6%

    17.01 ms31.21 msRun117.46 ms30.68 msRun218.55 ms31.16 msRun3sum(range(n)) (#b9c6d2) / sum(list(range(n))) (#2f6f4f)

    Conditions

    One million elements.

    Where this number does not apply

    If the list already exists, this gap is irrelevant.

    Reproduce

    cd bench && python micro_py.py --out ../data/run.json --samples 21