Move time tracking functions to separate file.

Former-commit-id: ccecc95fd70f36208fa01b3b4d2c7bdd1546ff92
This commit is contained in:
Marek Nečada 2017-05-10 11:43:11 +03:00
parent da45e0fdb4
commit 3a1f7c95aa
2 changed files with 33 additions and 29 deletions

View File

@ -8,35 +8,7 @@ import scipy
import sys
from qpms_c import get_mn_y, trans_calculator # TODO be explicit about what is imported
from .qpms_p import cart2sph, nelem2lMax # TODO be explicit about what is imported
def _time_b(active = True, name = None, step = None):
'''
Auxiliary function for keeping track of elapsed time.
Returns current time (to be used by _time_e).
'''
now = time.time()
if active:
if not name:
name = sys._getframe(1).f_code.co_name
if step:
print('%.4f: %s in function %s started.' % (now, step, name), file = sys.stderr)
else:
print('%.4f: Function %s started.' % (now, name), file=sys.stderr)
sys.stderr.flush()
return now
def _time_e(start_time, active = True, name = None, step = None):
now = time.time()
if active:
if not name:
name = sys._getframe(1).f_code.co_name
if step:
print('%.4f: %s in function %s finished (elapsed %.2f s).'
% (now, step, name, now - start_time), file = sys.stderr)
else:
print('%.4f: Function %s finished (elapsed %.2f s).'
% (now, name, now - start_time), file = sys.stderr)
sys.stderr.flush()
from .timetrack import _time_b, _time_e
class Scattering(object):
'''

32
qpms/timetrack.py Normal file
View File

@ -0,0 +1,32 @@
import time
import sys
def _time_b(active = True, name = None, step = None):
'''
Auxiliary function for keeping track of elapsed time.
Returns current time (to be used by _time_e).
'''
now = time.time()
if active:
if not name:
name = sys._getframe(1).f_code.co_name
if step:
print('%.4f: %s in function %s started.' % (now, step, name), file = sys.stderr)
else:
print('%.4f: Function %s started.' % (now, name), file=sys.stderr)
sys.stderr.flush()
return now
def _time_e(start_time, active = True, name = None, step = None):
now = time.time()
if active:
if not name:
name = sys._getframe(1).f_code.co_name
if step:
print('%.4f: %s in function %s finished (elapsed %.2f s).'
% (now, step, name, now - start_time), file = sys.stderr)
else:
print('%.4f: Function %s finished (elapsed %.2f s).'
% (now, name, now - start_time), file = sys.stderr)
sys.stderr.flush()