Notes on evaluating Δ_n factor in the lattice sums.
[qpms.git] / qpms / timetrack.py
blob358c2b8913804f6f4435228c62b08fa259deb01f
1 import time
2 import sys
4 def _time_b(active = True, name = None, step = None):
5 '''
6 Auxiliary function for keeping track of elapsed time.
7 Returns current time (to be used by _time_e).
8 '''
9 now = time.time()
10 if active:
11 if not name:
12 name = sys._getframe(1).f_code.co_name
13 if step:
14 print('%.4f: %s in function %s started.' % (now, step, name), file = sys.stderr)
15 else:
16 print('%.4f: Function %s started.' % (now, name), file=sys.stderr)
17 sys.stderr.flush()
18 return now
20 def _time_e(start_time, active = True, name = None, step = None):
21 now = time.time()
22 if active:
23 if not name:
24 name = sys._getframe(1).f_code.co_name
25 if step:
26 print('%.4f: %s in function %s finished (elapsed %.2f s).'
27 % (now, step, name, now - start_time), file = sys.stderr)
28 else:
29 print('%.4f: Function %s finished (elapsed %.2f s).'
30 % (now, name, now - start_time), file = sys.stderr)
31 sys.stderr.flush()