Source code for mat_discover.utils.Timer

"""Timer class."""
from time import time

[docs]class Timer(object): """Simple timer class. Usage ----- >>> with Timer("add two numbers"): ... out = 56 + 74 """
[docs] def __init__(self, name=None): """Assign name for Timer object.""" = name
def __enter__(self): """Enter the timer.""" self.tstart = time() def __exit__(self, type, value, traceback): """Exit the timer.""" if print( "[%s]" %, ) print(("Elapsed: {}\n").format(round((time() - self.tstart), 5)))
[docs]class NoTimer(object): """Use in place of Timer without actually printing output."""
[docs] def __init__(self, name): """Take name as argument and do nothing.""" pass