def stop(name=None, **kwargs): """ Stop a timer. Arguments: name (str, optional): The name of the timer to stop. If no name is given, stop the global anonymous timer. Raises: TimerNameError: If the named timer does not exist. """ name = name or _GLOBAL_TIMER if name not in _timers: if name == _GLOBAL_TIMER: raise Error("Global timer has not been started") else: raise TimerNameError("No timer named '{}'".format(name)) elapsed = int(round(_stop_timer(name))) if name == _GLOBAL_TIMER: name = "Timer" io.prof("{}: {} ms".format(name, elapsed), **kwargs)
def test_prof(): out = StringIO() io.prof("foo", file=out) assert "PROF" == re.search("PROF", out.getvalue()).group(0)
def test_prof(self): out = StringIO() io.prof("foo", file=out) self._test("PROF", re.search("PROF", out.getvalue()).group(0))