1
0

situtils.py 553 B

1234567891011121314151617181920212223
  1. import numpy as np
  2. import time
  3. class FPSTimes:
  4. def __init__(self, buffer=100):
  5. self.frame_times = []
  6. self.buffer = buffer
  7. def count(self):
  8. self.frame_times.append(time.time())
  9. if len(self.frame_times) > self.buffer:
  10. self.frame_times.pop(0)
  11. def get_time_diffs(self):
  12. return np.diff(np.array(self.frame_times))
  13. def get_avg_fps(self):
  14. diffs = self.get_time_diffs()
  15. if len(diffs) > 0:
  16. return (1.0/diffs).mean()
  17. return 0