MCPcopy Create free account
hub / github.com/blacklanternsecurity/bbot / SpeedCounter

Class SpeedCounter

bbot/scanner/stats.py:15–36  ·  view source on GitHub ↗

A simple class for keeping a rolling tally of the number of events inside a specific time window

Source from the content-addressed store, hash-verified

13
14
15class SpeedCounter:
16 """
17 A simple class for keeping a rolling tally of the number of events inside a specific time window
18 """
19
20 def __init__(self, window=60):
21 self.timestamps = deque()
22 self.window = window
23
24 def tick(self):
25 current_time = time.time()
26 self.timestamps.append(current_time)
27 self.remove_old_timestamps(current_time)
28
29 def remove_old_timestamps(self, current_time):
30 while self.timestamps and current_time - self.timestamps[0] > self.window:
31 self.timestamps.popleft()
32
33 @property
34 def speed(self):
35 self.remove_old_timestamps(time.time())
36 return len(self.timestamps)
37
38
39class ScanStats:

Callers 2

test_speed_counterFunction · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 1

test_speed_counterFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…