Skip to content

mikf/perf.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages