Pyベンチ実測MEASURED, NOT RECALLED

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

    append ループ is ~1.11× slower than リスト内包表記

    A list comprehension is ~11% faster than an append loop.

    Result

    Runappend ループリスト内包表記Ratio
    Run 119.18117.2921.11×
    Run 218.61716.9081.10×
    Run 319.26417.4641.10×

    Spread over 3 runs: append ループ CV 1.5% / リスト内包表記 CV 1.3% / Ratio CV 0.3%

    19.18 ms17.29 msRun118.62 ms16.91 msRun219.26 ms17.46 msRun3append ループ (#b9c6d2) / リスト内包表記 (#2f6f4f)

    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