Sha*_*kan 3 python performance memoization cprofile
假设我是一个从给定参数创建字典的方法:
def newDict(a,b,c,d): # in reality this method is a bit more complex, I've just shortened for the sake of simplicity
return { "x": a,
"y": b,
"z": c,
"t": d }
Run Code Online (Sandbox Code Playgroud)
我有另一种方法,每次执行时调用newDict方法.因此,最后,当我看到我的cProfiler时,我看到这样的事情:
17874 calls (17868 primitive) 0.076 CPU seconds
Run Code Online (Sandbox Code Playgroud)
当然,我的newDict方法被称为1785时间.现在,我的问题是我是否可以记住newDict方法以减少通话时间?(只是为了确保,变量几乎在每个调用中都会发生变化,但我不确定它是否对记忆函数有影响)
子问题:我认为17k调用太多,代码效率不高.但是,通过查看统计数据,您还可以说明这是正常结果还是我有太多的电话而代码很慢?
memoize没有memorize.