def test_TimerStatsAll(self): t = SmartTimer() for i in range(5): t.tic('loop ' + str(i)) t.sleep(0.2) t.toc() stats = t.stats() print(stats) self.assertAlmostEqual(0.2, stats.min[0], 1) self.assertAlmostEqual(0.2, stats.max[0], 1) self.assertAlmostEqual(0.2, stats.avg[0], 1)
# Create a timer instance named 'Example' t = SmartTimer("Example") # Print clock details t.tic("info") t.print_info() t.toc() # Measure iterations in a loop t.tic("loop") for i in range(10): t.tic("iter " + str(i)) sum(range(1000000)) t.toc() t.toc() t.tic("sleep") t.sleep(2) t.toc() # Write times to file 'Example.txt' t.to_file() print(t.times) print(t["info"]) print(t.walltime()) print(t) # Print stats only for labels with keyword 'iter' print(t.stats("iter"))