Skip to content

profiling module

Utilities for profiling time and memory.


timeit function

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

Run timeit() on a function.

Usage

>>> from vectorbtpro import *

>>> def my_func():
...     sleep(1)

>>> elapsed = vbt.timeit(my_func)
>>> print(elapsed)
1.01 seconds

>>> vbt.timeit(my_func, readable=False)
datetime.timedelta(seconds=1, microseconds=1870)

with_memtracer function

with_memtracer(
    *args,
    memtracer_kwargs=None,
    usage_kwargs=None,
    print_func=None,
    print_format=None,
    print_kwargs=None
)

Decorator to run a function with MemTracer.


with_timeit function

with_timeit(
    *args,
    timeit_kwargs=None,
    print_func=None,
    print_format=None,
    print_kwargs=None
)

Decorator to run a function with timeit().


with_timer function

with_timer(
    *args,
    timer_kwargs=None,
    elapsed_kwargs=None,
    print_func=None,
    print_format=None,
    print_kwargs=None
)

Decorator to run a function with Timer.


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)

>>> print(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)

>>> print(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.