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

# profiling module

Utilities for profiling time and memory.

## timeit function

    timeit(
        func,
        readable=True,
        **kwargs
    )

Run timeit() on a function.

## MemTracer class

    MemTracer()

Context manager to trace peak and final memory usage using `tracemalloc`.

Usage

    >>> from vectorbtpro import *

    >>> with vbt.MemTracer() as tracer:
    >>>     np.random.uniform(size=1000000)

    >>> tracer.peak_usage()
    '8.0 MB'

    >>> tracer.peak_usage(readable=False)
    8005360

### final_usage method

    MemTracer.final_usage(
        readable=True,
        **kwargs
    )

Get final memory usage.

`**kwargs` are passed to `humanize.naturalsize`.

### peak_usage method

    MemTracer.peak_usage(
        readable=True,
        **kwargs
    )

Get peak memory usage.

`**kwargs` are passed to `humanize.naturalsize`.

## Timer class

    Timer()

Context manager to measure execution time using timeit().

Usage

    >>> from vectorbtpro import *

    >>> with vbt.Timer() as timer:
    >>>     sleep(1)

    >>> timer.elapsed()
    '1.01 seconds'

    >>> timer.elapsed(readable=False)
    datetime.timedelta(seconds=1, microseconds=5110)

### elapsed method

    Timer.elapsed(
        readable=True,
        **kwargs
    )

Get elapsed time.

`**kwargs` are passed to `humanize.precisedelta`.

### end_time property

End time.

### start_time property

Start time.

#### 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