Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- # Timing utils
- class TimingsTot:
- def __init__(self, path = None, title = "insert date time here", debug_mode = True):
- self.starttime = time.perf_counter()
- self.nowtime = time.perf_counter()
- self.lastcall = time.perf_counter()
- self.logfilepath = path
- self.debug_mode = debug_mode
- with open(self.logfilepath, 'a') as f:
- f.write("--------"+ title + "---------\n")
- def convert_in_ddhhss(self, seconds):
- hh = 0
- mm = 0
- ss = 0
- mm, ss = divmod(int(seconds), 60)
- hh, mm = divmod(mm, 60)
- return "{0:0>2}:{1:0>2}:{2:0>2}".format(hh, mm, ss)
- def gettimestr(self):
- self.nowtime = time.perf_counter()
- subtime = self.nowtime - self.lastcall
- subtime = self.convert_in_ddhhss(subtime)
- s = "Elapsed time for subprocess: {0}\n".format(subtime)
- totaltime = self.nowtime - self.starttime
- totaltime = self.convert_in_ddhhss(totaltime)
- s += "Total elapsed time: {0}".format(totaltime)
- self.lastcall = time.perf_counter()
- return s
- def logtimestr(self, title):
- s = self.gettimestr()
- if self.logfilepath != None:
- with open(self.logfilepath, 'a') as f:
- f.write(title + '\n')
- f.write(s + '\n')
- if self.debug_mode:
- print(title)
- print(s)
- def __str__(self):
- s = 'Not available'
- return s
Advertisement
Add Comment
Please, Sign In to add comment