Timer

class vindinium.utils.Timer(do_print=False)[source]

Bases: object

Timer helper.

A timer object helps to verify how much time has been taken to execute some code.

Example

You can use this class in two ways. First as a with statement:

with Timer() as timer:
    # your code here
print timer.elapsed

Notice that you can pass True as argument to Timer in order to allow it to print the elapsed time when the with finishes.

Alternatively, you can use Timer like the tic toc functions of Matlab:

timer = Timer()
timer.tic()
# your code here
print timer.toc()
elapsed

float

the elapsed time between tic() and toc().

__enter__()[source]

Enters with

__exit__(type, value, traceback)[source]

Leaves with

__init__(do_print=False)[source]

Constructor.

Parameters:do_print (bool) – whether timer should print the result after with ends or not. Default to False.
tic()[source]

Start the timer.

toc()[source]

Stops the timer and returns the elapsed time.

Returns:(float) the elapsed time.