This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def timeit(f): | |
def timed(*args, **kw): | |
ts = time.time() | |
result = f(*args, **kw) | |
te = time.time() | |
print("function time {} : {} sec".format(f.__name__, te - ts)) | |
return result | |
return timed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def memoize(obj): | |
cache = obj.cache = {} | |
@functools.wraps(obj) | |
def memoizer(*args, **kw): | |
if args not in cache: | |
cache[args] = obj(*args, **kw) | |
return cache[args] | |
return memoizer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from functools import wraps | |
from multiprocessing.context import TimeoutError | |
from multiprocessing.pool import ThreadPool | |
def timeout(seconds): | |
def timeout_wrapper(func): | |
@wraps(func) | |
def wrapped(*args, **kwargs): |