Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

#
Benchmarking

To measure execution time of a code block by running it only once, use Timer.

Measure execution time by running once

    with vbt.Timer() as timer:
        my_pipeline()

    print(timer.elapsed())

Note

The code block may depend on Numba functions that need to be compiled first. To exclude any compilation time from the estimate (recommended since a compilation may take up to a minute while the code block may execute in milliseconds), dry-run the code block.

Another way is to repeatedly run a code block and assess some statistic, such as the shortest average execution time, which is easily doable with the help of the timeit module and the corresponding vectorbtpro's function that returns the number in a human-readable format. The advantage of this approach is that any compilation overhead is effectively ignored.

Measure execution time by running multiple times

    print(vbt.timeit(my_pipeline))

There's also a profiling tool for peak memory usage - MemTracer, which helps to determine an approximate size of all objects that are generated when running a code block.

Measure peak memory usage by running once

    with vbt.MemTracer() as tracer:
        my_pipeline()

    print(tracer.peak_usage())

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings