Mercurial > code > home > repos > light9
annotate light8/updatefreq.py @ 120:b75bfbcf5979
new modules: dmxclient provides a very convenient way for clients to talk to the
new modules: dmxclient provides a very convenient way for clients to talk to the
dmxserver; updatefreq stores event times and computes a report about how frequently
they occur
author | drewp |
---|---|
date | Fri, 13 Jun 2003 14:00:36 +0000 |
parents | 45b12307c695 |
children | 57809e0ef359 |
rev | line source |
---|---|
0 | 1 """calculates your updates-per-second""" |
2 | |
3 import time | |
4 | |
5 class Updatefreq: | |
6 """make one of these, call update() on it as much as you want, | |
7 and then float() or str() the object to learn the updates per second. | |
8 | |
9 the samples param to __init__ specifies how many past updates will | |
10 be stored. """ | |
11 | |
120
b75bfbcf5979
new modules: dmxclient provides a very convenient way for clients to talk to the
drewp
parents:
0
diff
changeset
|
12 def __init__(self,samples=40): |
0 | 13 self.times=[0] |
14 self.samples=samples | |
15 | |
16 def update(self): | |
17 | |
18 """call this every time you do an update""" | |
19 self.times=self.times[-self.samples:] | |
20 self.times.append(time.time()) | |
21 | |
22 def __float__(self): | |
23 | |
24 """a cheap algorithm, for now, which looks at the first and | |
25 last times only""" | |
26 | |
120
b75bfbcf5979
new modules: dmxclient provides a very convenient way for clients to talk to the
drewp
parents:
0
diff
changeset
|
27 hz=len(self.times)/(self.times[-1]-self.times[0]) |
0 | 28 return hz |
29 def __str__(self): | |
120
b75bfbcf5979
new modules: dmxclient provides a very convenient way for clients to talk to the
drewp
parents:
0
diff
changeset
|
30 return "%.1fHz"%float(self) |