2018-08-20 23:00:22 +00:00
|
|
|
import os
|
2018-11-02 12:01:37 +00:00
|
|
|
import time
|
|
|
|
|
from functools import wraps
|
2018-08-20 23:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def jj(*args):
|
|
|
|
|
return os.path.join(*args)
|
2018-11-02 12:01:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Timer(object):
|
|
|
|
|
def __init__(self, verbose=False):
|
|
|
|
|
self.verbose = verbose
|
|
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
|
self.start = time.time()
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
|
self.end = time.time()
|
|
|
|
|
self.secs = self.end - self.start
|
|
|
|
|
self.msecs = self.secs * 1000 # millisecs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def profile(fn):
|
|
|
|
|
@wraps(fn)
|
|
|
|
|
def with_profiling(*args, **kwargs):
|
|
|
|
|
with Timer() as t:
|
|
|
|
|
ret = fn(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
return ret, t.secs
|
|
|
|
|
|
|
|
|
|
return with_profiling
|