unitbench / src / doc / api.rst

API Documentation

This is the documentation for the classes contained in unitbench.


This is the main class to extend when using unitbench to write benchmarks similar to unit tests.


This is the function profiler. Rather than a general profiler which profiles every function, this profiles specific functions as you choose. It is used as a function decorator applied to functions you're interested in seeing the performance. It can track the parameters used to call the given function also. If your function is slow for a given input, that could be tracked using the FunctionProfiler.

Here is a quick example:

fp = FunctionProfiler()

def fib(n):
    if n == 1 or n == 0:
        return n
    return fib(n - 1) + fib(n - 2)



This is the default reporter for unitbench. It will it writes out results in the following format:

Will write the output formatted as above to the given file-type stream. It does not open or close the stream, so make sure to handle that outside of this method.

The only method called on the stream is write(str), so any object with a write function should work.


This is an alternative reporter for unitbench. It writes the output to a csv format for easy ingestion into spreadsheet programs.

As with the ConsoleReporter this reporter also takes a stream to write its output. It also has a second parameter time_type. time_type can be "wall", "system", or "user". It denotes which type of time for which to retrieve the average.

Type Definition
wall Wall clock time.
user User CPU time.
system System or kernel CPU time.



Using this class is only necessary if you're writing a new results reporter. It is passed into the write_results method of the various reporters.