#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 作者: Apollo
# 邮箱: 1986690272@qq.com
# 博客: http://www.zgerji.online/

import time

flag = True


def timmer_out(f):
    def timmer(func):
        def inner(*args, **kwargs):
            '''执行函数前操作'''
            if f:
                start_time = time.time()
                time.sleep(0.3)
                ret = func(*args, **kwargs)
                '''执行函数后操作'''
                end_time = time.time()
                print('执行效率%s' % (end_time - start_time))
                return ret
            else:
                ret = func(*args, **kwargs)
                return ret

        return inner

    return timmer

# timmer_out(flag),返回timmer
@timmer_out(flag)
# @timmer,就是你认识的装饰器,f1 = timmer(f1)
def f1():
    print(666)


@timmer_out(flag)  # f2 = timmer(f2)
def f2():
    print(777)


f1()
f2()