-
Notifications
You must be signed in to change notification settings - Fork 12
/
timed.py
40 lines (33 loc) · 1.1 KB
/
timed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import time
import collections
def timeit(f):
def timed(*args, **kw):
ts = time.time()
result = f(*args, **kw)
te = time.time()
# print('func:%r args:[%r, %r] took: %2.4f sec' % (f.__name__, args, kw, te-ts))
print('func:%r took: %2.4f sec' % (f.__name__, te-ts))
return result
return timed
class Timer:
def __init__(self,name="DefaultTimer",silent=False):
self.starttime = time.time()
self.name = name
self.silent = silent
def tick(self,message=""):
if not self.silent:
now = time.time()
print('%r: %r:%2.4f s' % (self.name, message, now-self.starttime))
def reset():
self.starttime = time.time()
def pause():
pass
class FPS:
def __init__(self,avarageof=50):
self.frametimestamps = collections.deque(maxlen=avarageof)
def __call__(self):
self.frametimestamps.append(time.time())
if(len(self.frametimestamps) > 1):
return len(self.frametimestamps)/(self.frametimestamps[-1]-self.frametimestamps[0])
else:
return 0.0