python用装饰器去对比type函数和isinstance函数运行时间

2019年3月29日00:14:30 发表评论 499 views
import time
str1 = 'aaaaa'
def run_timefunc(func):
    def new_func(*args,**kwargs):
        t0 = time.time()
        func()
        # back = func(*args,**kwargs)
        print('函数运行时间%s'%(time.time()-t0))
        return
    return new_func()
@run_timefunc
def com3():
    for i in range(0,10000000):
        type('aaa')
@run_timefunc
def com2():
    for i in range(0,10000000):
        isinstance('aaa',str)
com3()
com2()

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: