我有一个我正在分析的小片段,但是list comprehension
在调用中作为一个项目列出
import fileinput
import cProfile
pr = cProfile.Profile()
pr.enable()
x = [float(i) for i in range(0, 10**8)]
pr.disable()
pr.print_stats(sort='time')
输出:
2 function calls in 19.769 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 19.769 19.769 19.769 19.769 sandboxMinimalCProfile.py:6(<listcomp>)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
例如,有没有可能得到转换成float
的成本?你知道吗
这里的问题是
float
是一个内置的,所以它们不算作对探查器的调用。你知道吗您可以尝试解决这个问题;但是,探查器在任何情况下都不是为微基准而设计的。相反,请尝试^{} standard module :
相关问题 更多 >
编程相关推荐