📜  时间装饰器python代码示例

📅  最后修改于: 2022-03-11 14:46:25.998000             🧑  作者: Mango

代码示例1
from functools import wraps
from time import time
def measure(func):
    @wraps(func)
    def _time_it(*args, **kwargs):
        start = int(round(time() * 1000))
        try:
            return func(*args, **kwargs)
        finally:
            end_ = int(round(time() * 1000)) - start
            print(f"Total execution time: {end_ if end_ > 0 else 0} ms")
    return _time_it
@measure
def hello():
    print('hello world')

hello()