def test_RecordTime(self): t = Timer() t.time() self.assertEqual(t.label, '') self.assertGreater(t.seconds, 0.) self.assertGreater(t.minutes, 0.) self.assertEqual(t.clock_name, Timer.DEFAULT_CLOCK_NAME)
def test_Reset(self): t = Timer('timer1', clock_name='process_time') t.time() t.reset() self.assertEqual(t.label, '') self.assertEqual(t.seconds, 0.) self.assertEqual(t.minutes, 0.) self.assertEqual(t.clock_name, Timer.DEFAULT_CLOCK_NAME)
def test_InitOtherTimer(self): t = Timer('timer1') t.time() t2 = Timer('timer2', timer=t) self.assertNotEqual(t.label, t2.label) self.assertEqual(t.seconds, t2.seconds) self.assertEqual(t.minutes, t2.minutes) self.assertEqual(t.clock_name, t2.clock_name)
def test_Clear(self): # Assumes 'process_time' is a valid clock and not the default one. t = Timer('timer1', clock_name='process_time') t.time() t.clear() self.assertEqual(t.label, 'timer1') self.assertEqual(t.seconds, 0.) self.assertEqual(t.minutes, 0.) self.assertNotEqual(t.clock_name, Timer.DEFAULT_CLOCK_NAME)
def test_RegisterClock(self): TestStack.push(Timer.CLOCKS) Timer.register_clock('constant_time', constant_time) t = Timer() t.clock_name = 'constant_time' t.time() self.assertEqual(t.clock_name, 'constant_time') self.assertAlmostEqual(t.seconds, 1.) self.assertAlmostEqual(t.minutes, 1. / 60.) Timer.CLOCKS = TestStack.pop()
from smarttimers import Timer # Find the current time function of a Timer t1 = Timer('Timer1') print(Timer.CLOCKS[t1.clock_name]) # or Timer.print_clocks() print(t1.clock_name) # Change current time function t1.clock_name = 'process_time' # Record a time measurement t1.time() print(t1) # Create another Timer compatible with 'Timer1' t2 = Timer('Timer2', clock_name='process_time') t2.print_info() t2.time() print(t2) # Sum Timers t3 = Timer.sum(t1, t2) # or t3 = t1 + t2 print(t3) # Find difference between Timers t4 = Timer.diff(t1, t2) # or