23 lines
674 B
Python
23 lines
674 B
Python
import time
|
|
|
|
def Singleton(class_):
|
|
instances = {}
|
|
def getinstance(*args, **kwargs):
|
|
if class_ not in instances:
|
|
instances[class_] = class_(*args, **kwargs)
|
|
return instances[class_]
|
|
return getinstance
|
|
|
|
def Timed(method):
|
|
def timed(*args, **kw):
|
|
ts = time.time()
|
|
result = method(*args, **kw)
|
|
te = time.time()
|
|
if 'log_time' in kw:
|
|
name = kw.get('log_name', method.__name__.upper())
|
|
kw['log_time'][name] = int((te - ts) * 1000)
|
|
else:
|
|
print('%r total execution time was %2.2f ms' % (method.__name__, (te - ts) * 1000))
|
|
return result
|
|
return timed
|