-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
27 lines (21 loc) · 811 Bytes
/
utils.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
# -*- coding: utf-8 -*-
import os
import time
import click
PROJECT_PATH = os.path.dirname(__file__)
RESULTS_PATH = os.path.join(PROJECT_PATH, 'results')
MODEL_CACHE_PATH = os.path.join(PROJECT_PATH, 'model_cache')
def measure_time(fun):
def inner(self, *args, **kwargs):
start_time = time.process_time()
result = fun(self, *args, **kwargs)
elapsed_sec = round(time.process_time() - start_time, 2)
msg = self.function.__name__ if hasattr(self, 'function') else self.__class__.__name__
click.secho('Finished {} in {} sec'.format(msg, elapsed_sec), fg='yellow')
return result
return inner
def timeit(fun, *args, **kwargs):
start_time = time.process_time()
fun(*args, **kwargs)
duration = time.process_time() - start_time
return duration