| 2 | import datetime |
| 3 | |
| 4 | class FPS: |
| 5 | def __init__(self): |
| 6 | # store the start time, end time, and total number of frames |
| 7 | # that were examined between the start and end intervals |
| 8 | self._start = None |
| 9 | self._end = None |
| 10 | self._numFrames = 0 |
| 11 | |
| 12 | def start(self): |
| 13 | # start the timer |
| 14 | self._start = datetime.datetime.now() |
| 15 | return self |
| 16 | |
| 17 | def stop(self): |
| 18 | # stop the timer |
| 19 | self._end = datetime.datetime.now() |
| 20 | |
| 21 | def update(self): |
| 22 | # increment the total number of frames examined during the |
| 23 | # start and end intervals |
| 24 | self._numFrames += 1 |
| 25 | |
| 26 | def elapsed(self): |
| 27 | # return the total number of seconds between the start and |
| 28 | # end interval |
| 29 | return (self._end - self._start).total_seconds() |
| 30 | |
| 31 | def fps(self): |
| 32 | # compute the (approximate) frames per second |
| 33 | return self._numFrames / self.elapsed() |
no outgoing calls
no test coverage detected