-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeveloper.py
53 lines (42 loc) · 1.53 KB
/
developer.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
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import pkgutil
import importlib
import time
chronicle = []
class Benchmark():
def __init__(self, do_benchmark):
if do_benchmark:
os.system("clear")
self.do_benchmark = do_benchmark
self.start_time = self.time = time.time()
self.chronicle = []
def measure(self, name=""):
if self.do_benchmark:
t = time.time() - self.time
self.time += t
self.chronicle.append(t)
global chronicle
if chronicle:
diff = self.chronicle[-1] - chronicle[len(self.chronicle) - 1]
diff = "+ %.6f" % diff if diff > 0 else ("%.6f" % diff).replace("-", "- ")
print("--- %f (%s) - %s" % (t, diff, name))
else:
print("--- %f - %s" % (t, name))
def total(self):
if self.do_benchmark:
t = time.time() - self.start_time
self.chronicle.append(t)
global chronicle
if chronicle:
diff = self.chronicle[-1] - chronicle[len(self.chronicle) - 1]
diff = "+ %.6f" % diff if diff > 0 else ("%.6f" % diff).replace("-", "- ")
print(" » %f (%s) - %s" % (t, diff, "total"))
else:
print(" » %f - %s" % (t, "total"))
chronicle = self.chronicle
def output_traceback(self):
import traceback
print()
traceback.print_exc()
tb = traceback.format_exc() + "\nPLEASE REPORT THIS ERROR to [email protected]"
self.report({'ERROR'}, tb)