def time_elapsed(func):
    """
    记录函数运行耗时的生成器
    :param func:
    :return:
    """

    @wraps(func)
    def wrapper(*args, **kwargs):
        timestamp = time.time() * 1000
        ret = func(*args, **kwargs)
        now_ts = time.time() * 1000
        elapsed = now_ts - timestamp
        print('%s costs time: %.2fms' % (func.__name__, elapsed))
        return ret

    return wrapper