Pyベンチ実測MEASURED, NOT RECALLED

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

    正規表現 is ~2.33× slower than startswith

    For a fixed prefix, `startswith` is ~2.3× faster than a compiled regex.

    Result

    Runstartswith正規表現Ratio
    Run 123.52357.2760.41×
    Run 222.85354.7150.42×
    Run 324.04254.0420.44×

    Spread over 3 runs: startswith CV 2.1% / 正規表現 CV 2.5% / Ratio CV 3.5%

    23.52 ms57.28 msRun122.85 ms54.71 msRun224.04 ms54.04 msRun3startswith (#b9c6d2) / 正規表現 (#2f6f4f)

    Conditions

    200,000 words tested for the prefix `seg`; the regex is pre-compiled.

    Where this number does not apply

    If the pattern is dynamic or complex, a regex is the only option and this comparison does not apply.

    Reproduce

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