Utility class for measuring steps/second.
| 582 | |
| 583 | |
| 584 | class StepTimer: |
| 585 | """Utility class for measuring steps/second.""" |
| 586 | |
| 587 | def __init__(self, step): |
| 588 | self.step = step |
| 589 | self.start() |
| 590 | |
| 591 | def start(self): |
| 592 | self.last_iteration = self.step.numpy() |
| 593 | self.last_time = time.time() |
| 594 | |
| 595 | def steps_per_second(self, restart=True): |
| 596 | value = ((self.step.numpy() - self.last_iteration) / |
| 597 | (time.time() - self.last_time)) |
| 598 | if restart: |
| 599 | self.start() |
| 600 | return value |