Timer#

Module provides tools for timing information.

Example

>>> import ClearMap.Utils.Timer as timer
>>> t = timer.Timer();
>>> for i in range(100000000):
>>>   x = 10 + i;
>>> t.print_elapsed_time('test')
class Timer(head=None)[source]#

Bases: object

Class to stop time and print results in formatted way

time#

The time since the timer was started.

Type:

float

head#

Option prefix to the timing string.

Type:

str or None

elapsed_time(head=None, as_string=True)[source]#

Calculate elapsed time and return as formated string

Arguments

headstr or None

Prefix to the timing string.

as_stringbool

If True, return as string, else return elapsed time as float.

Returns

timestr or float

The elapsed time information.

format_time(t)[source]#

Format time to string.

Arguments

t :float

Time in seconds to format.

Returns

timestr

The time as ‘hours:minutes:seconds:milliseconds’.

print_elapsed_time(head=None, beep=False)[source]#

Print elapsed time.

Arguments

headstr or None

Prefix to the timing string.

beepbool

If True, beep in addition to print the time.

reset()[source]#

Reset the timer

start()[source]#

Start the timer

timeit(method)[source]#