Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (18 sloc) 647 Bytes
from datetime import datetime
class CountsPerSec:
Class that tracks the number of occurrences ("counts") of an
arbitrary event and returns the frequency in occurrences
(counts) per second. The caller must increment the count.
def __init__(self):
self._start_time = None
self._num_occurrences = 0
def start(self):
self._start_time =
return self
def increment(self):
self._num_occurrences += 1
def countsPerSec(self):
elapsed_time = ( - self._start_time).total_seconds()
return self._num_occurrences / elapsed_time