Skip to main content

Python benchmark tool

Project description


Python benchmark library


pip3 install bma_benchmark


from bma_benchmark import benchmark

def benchmark1():
    # do some job
    1 + 1

def my_function2():
    # do some job
    1 * 1
# equal to
#    number=100, precision=3, units='s', print_result=True, sort_result='desc')


Decorator arguments

  • name override benchmark name (default: function name)

  • base use as the base benchmark to measure difference from (True/False) arguments

  • number number of function executions

  • precision digits after comma for numbers

  • units min/max/avg units (s, ms, us or ns)

  • print_result automatically print results (True/False)

  • sort_result sort result in ascending (asc/a) or descending(desc/d) order, None to keep unsorted

Calling sub-processes

The module can call sub-processes to measure difference between different library versions in different virtual environments or between different versions of Python interpreter.

Primary script

from bma_benchmark import benchmark

# define some local benchmarks if required
def bench1():


Secondary scripts

make sure the scripts have execution permission (chmod +x):


from bma_benchmark import benchmark

# define benchmarks
def bench2():


The secondary scripts can contain "base" argument in a decorator as well. The "sub()" method outputs benchmark results to stdout in JSON format to synchronize with the primary, so secondary benchmarks must not print anything.

Multiple benchmarks in the same script

"benchmark" is the default benchmark object. Custom objects can be created from the "Benchmark class".

from bma_benchmark import Benchmark

my_bench = Benchmark()

def bench():

Storing results from multiple benchmarks

Run a benchmark script with "OUT" OS variable:

OUT=b1.json python

The benchmark result will be saved into "b1.json" file. After, multiple benchmarks can be combined into a single table with "bma-benchmark" console tool:

bma-benchmark b1.json b2.json

The tool automatically adds benchmark prefixes as "FILE_NAME.". It also has got options to specify precision, units etc. (run "bma-benchmark -h" to get list of all options)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bma_benchmark-0.0.6.tar.gz (5.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page