Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time.timeit 应该去除wrapt.dectator 自身的时间 #13

Open
wztdream opened this issue Apr 27, 2020 · 0 comments
Open

Time.timeit 应该去除wrapt.dectator 自身的时间 #13

wztdream opened this issue Apr 27, 2020 · 0 comments

Comments

@wztdream
Copy link

您好,
读过您写的书,收获很大,谢谢。
有一个疑问,如题。Time.timeit利用wrapt.dectator来计算一个函数的执行时间。通常是没有问题的。但是如果是一个嵌套函数,外层函数的计时就是:内层函数执行时间+wrapt 自身执行的时间。如果内层函数被执行n次,那么外层函数的计时时间就多出了n*(wrapt 自身执行时间),这可能导致时间分析不准确。比如下面的例子, outer()的总时间被错误的多计时了(100000000*wrap时间)。不知道有没有办法在wrapt之间进行通讯,来扣除内部wrapt 自身的时间(不是inner函数的执行时间哈)

@timing.timeit()
def inner():
    print("inner")
@timing.timeit()
def outter():
   for i in range(100000000):
        inner()
    print("outer")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant