mikf/perf.py

Command-line tool to benchmark and compare Python code with minimal overhead

9

stars

26

commits

Python

primary language

Jan 17, 2026

updated

benchmark
performance
python

README

perf.py

A simple command-line tool to benchmark Python code.


Usage:

    $ perf.py --help
    usage: perf.py [OPTION]... PATH

    options:
      -h, --help               Print this help message and exit
      --version                Print program version and exit
      -S, --show-source        Display generated benchmark code
      -B, --show-bytecode      Display bytecode
      -R, --show-results       Display return values
      -P, --show-python        Display Python version
      -n, --iterations N       Number of iterations
      -t, --threshold SECONDS  Number of seconds to run a benchmark for
      -g, --gc                 Enable garbage collection during benchmark runs
      -l, --loop               Keep loop overhead in benchmark timings


Example:

    $ cat benchmark.py

    NAME = "filename.tar.gz"

    def split():
        return NAME.split(".")[-1]

    def rsplit():
        return NAME.rsplit(".", 1)[1]

    def rpartition():
        return NAME.rpartition(".")[2]


    $ perf.py benchmark.py
    split     : 146.13ns  1.00
    rsplit    : 128.06ns  0.88
    rpartition: 106.97ns  0.73

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

Contributors

mikf

26 commits

mikf/perf.py

Command-line tool to benchmark and compare Python code with minimal overhead

9

stars

26

commits

Python

primary language

Jan 17, 2026

updated

benchmark
performance
python

README

perf.py

A simple command-line tool to benchmark Python code.


Usage:

    $ perf.py --help
    usage: perf.py [OPTION]... PATH

    options:
      -h, --help               Print this help message and exit
      --version                Print program version and exit
      -S, --show-source        Display generated benchmark code
      -B, --show-bytecode      Display bytecode
      -R, --show-results       Display return values
      -P, --show-python        Display Python version
      -n, --iterations N       Number of iterations
      -t, --threshold SECONDS  Number of seconds to run a benchmark for
      -g, --gc                 Enable garbage collection during benchmark runs
      -l, --loop               Keep loop overhead in benchmark timings


Example:

    $ cat benchmark.py

    NAME = "filename.tar.gz"

    def split():
        return NAME.split(".")[-1]

    def rsplit():
        return NAME.rsplit(".", 1)[1]

    def rpartition():
        return NAME.rpartition(".")[2]


    $ perf.py benchmark.py
    split     : 146.13ns  1.00
    rsplit    : 128.06ns  0.88
    rpartition: 106.97ns  0.73

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

Contributors

mikf

26 commits

Languages

Python

100.0%