forked from tmhlsky/Instagram-API-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluation_log.py
More file actions
37 lines (28 loc) · 995 Bytes
/
Copy pathevaluation_log.py
File metadata and controls
37 lines (28 loc) · 995 Bytes
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
from time import time, process_time, strftime, localtime
from datetime import timedelta
def time_to_str(elapsed=None):
if elapsed is None:
return strftime("%Y-%m-%d %H:%M:%S", localtime())
else:
return str(timedelta(seconds=elapsed))
class EvaluationLog():
def start_log(self, s="Start Program"):
self.start = time()
self.cpu_start = process_time()
self.log(s)
def end_log(self, s="End Program"):
self.end = time()
self.cpu_end = process_time()
elapsed_time = self.end - self.start
cpu_time = self.cpu_end - self.cpu_start
self.log(s, time_to_str(elapsed_time), time_to_str(cpu_time))
@staticmethod
def log(s, elapsed_time=None, cpu_time=None):
line = "=" * 40
print(line)
print(time_to_str(), '-', s)
if elapsed_time:
print("Elapsed time:", elapsed_time)
if cpu_time:
print("CPU time:", cpu_time)
print(line)