def time_me(info="used", format_string="ms"):
"""Performance analysis - time
Decorator of time performance analysis.
????——????
????(wall clock time, elapsed time)???????????????????????
???????????CPU???????????????C++/Windows?????<time.h>???
??????????????????
1.time.clock()??????????????CPU????????????????time.time()????
time.clock()?????????????UNIX?????????"????"?????????????????
??WINDOWS????????????????????????????????????
???????????????????WIN32?QueryPerformanceCounter()???????????????
2.time.perf_counter()?????????????????????????????
???????????????????????
3.time.process_time()???????
Args:
info: Customize print info. ????????
format_string: Specifies the timing unit. ?????????'s': ??'ms': ???
Defaults to 's'.
"""
def _time_me(func):
@wraps(func)
def _wrapper(*args, **kwargs):
start = time.clock()
# start = time.perf_counter()
# start = time.process_time()
result = func(*args, **kwargs)
end = time.clock()
if format_string == "s":
print("%s %s %s"%(func.__name__, info, end - start), "s")
elif format_string == "ms":
print("%s %s %s" % (func.__name__, info, 1000*(end - start)), "ms")
return result
return _wrapper
return _time_me
评论列表
文章目录