-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeIt.py
More file actions
executable file
·55 lines (46 loc) · 1.58 KB
/
TimeIt.py
File metadata and controls
executable file
·55 lines (46 loc) · 1.58 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# TimeIt.py
import base64
import datetime
import json
import sys
import time
import unicodedata
from datetime import datetime, timedelta
from os import path
class TimeIt:
def _init_(self):
self.start = time.time()
self.data = [{'Desc': 'Timer Start', 'Took': 0, 'TS': self.start}]
self.debug = True if (len(sys.argv)>1 and sys.argv[1] == 'debug') else False
def myPrint(self, data=''):
if self.debug: print(data)
def set(self, desc='Timer'):
rs = sorted(self.data, key=lambda x: (x['TS']))
count = len(self.data)
ts= time.time()
to = self.data [count-1] ['TS']
took = str(round ((ts - to) * 1000,3))
self.data.append({'Desc': str(desc), 'Took': took, 'TS':ts})
return took
def toLen(self,s,l,d=' ',a='r'):
"""
s=character/number
l-length
d=repeated character
a=alignment r gor right and anything else for left
"""
c = str(s)
while len(c)<l:
c = d + c if a=='r' else c + d
return c
def get(self, out=False):
rs = sorted(self.data, key=lambda x: (x['TS']))
total = rs[len (rs)-1] ['TS'] - rs[0]['TS']
self.myPrint(self.toLen('TS',25,' ')+self.toLen('Took ms',10,)+' Desc')
self.myPrint(self.toLen('-',73,'-'))
for r in rs:
self.myPrint(self.toLen(r['TS'],25)+self.toLen(r['Took'], 10)+' '+r['Desc'])
self.myPrint(self.toLen('-',73,'-'))
self.myPrint('Took ms : '+str(total*1000))
return self.data