benchmark-decorator

As the name implies, it is a decorator that benchmarks functions


Keywords
benchmark, decorator
License
MIT
Install
pip install benchmark-decorator==2.1.1

Documentation

Benchmark Decorator

As the name implies, it is a decorator that benchmarks functions.

Check the file example.py to see it in action.

Installation

From PyPI

$ pip install benchmark-decorator

From Github

$ pip install git+https://github.com/werneckbh/benchmark-decorator.git

Usage

Just call it before any function you want to benchmark:

from benchmark import Benchmark


@Benchmark()
def my_function():
    pass

and whenever my_function runs, it will save to the bench.log file the time it took to run.

Optionally, you can change the file name of your log file.
Just add filename='filename.log' to the Benchmark constructor.

Other options include:

  • name: string default 'BENCHMARK'
  • save: boolean default True
  • filemode: string default 'w'
  • level: integer default logging.INFO
  • formatter: logging.Formatter default logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

Note

If you want to decorate multiple functions, it's best to instantiate the decorator only once.

from benchmark import benchmark


dec = Benchmark(filename='benchmark.log')


@dec
def my_func1():
    pass


@dec
def my_func2():
    pass

You can also have multiple benchmark decorators running at once. Just give them different names. Check the example.py file for more information.