embutils.utils.time module

Timing utilities.

date

2021

author

Christian Wiche

contact

cwichel@gmail.com

license

The MIT License (MIT)

class embutils.utils.time.Timer[source]

Bases: object

Simple process timer.

This class don’t require any input from the user to be initialized.

elapsed(update: bool = False) float[source]

Computes the time elapsed since the latest timer start.

Parameters

update (bool) – Computes elapsed time and updated the start time.

Returns

Time elapsed.

Return type

float

start() float[source]

Updates the timer start timestamp.

Returns

Start time.

Return type

float

embutils.utils.time.timer(name: typing.Optional[str] = None, logger: typing.Callable[[...], typing.Any] = <built-in function print>, precision: int = 6) Callable[[Callable[[...], Any]], Callable[[...], Any]][source]

Decorator. Used to log the execution time of a function.

Parameters
  • name (str) – Timer name. Used to identify the measurement.

  • logger (CBAny2Any) – Callable used to print the time logs. By default, system print.

  • precision (float) – Number of decimals included on elapsed time.

Returns

Decorated function wrapped on timer.

Return type

Callable[[Callable[…, RT]], Callable[…, RT]]