comixify/utils.py
Maciej Pęśko 6a2be40ea0
Add profiling (#11)
* Add profiling

* Fix decorators order
2018-11-02 13:01:37 +01:00

32 lines
621 B
Python

import os
import time
from functools import wraps
def jj(*args):
return os.path.join(*args)
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