Esempio n. 1
0
    def test_clear_timers(self):
        """Test clear timers"""
        t = Timer(matlab_like=False)
        for i in range(10):
            t.start(i)

        t.clear_timers()
        assert len(t._timers_start) == 0, "Timers not restarting"
Esempio n. 2
0
elapsed = t.stop()
print("Elapsed time:", elapsed)  # ~1 second

print("\nNested")
t.start(key="Init")
for i in range(2):
    t.start(key=i)
    time.sleep(1)
    elapsed = t.stop(key=i)
    print("[IN LOOP] Elapsed time:", elapsed)
print("[OUT LOOP] Elapsed time:", t.stop("Init"))

print("\n[OUT LOOP][Init] Elapsed time:", t.stop("Init"))
print("[OUT LOOP][0] Elapsed time:", t.stop(0))
print("[OUT LOOP][1] Elapsed time:", t.stop(1))
t.clear_timers()  # Delete all the timers, only works in not matlab-like mode

print("\n>>>Context Manager")
# Default
print("\nDefault")
with Timer():
    time.sleep(1)

# With out verbose
print("\nVerbose OFF")
with Timer(verbose=False) as T:
    time.sleep(1)
print("Elapsed time:", T.elapsed)

# With default verbose message
print("\nCustom Verbose")