(self)
| 21 | self.start_time = self.tic = time.time() |
| 22 | |
| 23 | def record(self): |
| 24 | self.count += 1 |
| 25 | self.toc = time.time() |
| 26 | self.current_time = self.toc - self.tic |
| 27 | self.total_time += self.current_time |
| 28 | # calculate average time |
| 29 | self.avg_time = self.total_time / self.count |
| 30 | |
| 31 | # reset |
| 32 | if self.count > self.window: |
| 33 | self.count = 0 |
| 34 | self.total_time = 0 |
| 35 | |
| 36 | self.tic = time.time() |
| 37 | |
| 38 | def get_current_time(self): |
| 39 | return self.current_time |