【发布时间】:2013-11-30 04:12:58
【问题描述】:
我正在尝试分析一些对str 进行大量调用的代码的性能,以查看是否可以从使用str 的其他方法中受益,但我无法获得@987654323 @ 告诉我调用str 花费了多少时间。
例如,如果我测试(废话)代码
def foo(n):
x = ''
for i in range(n):
x += str(n)
x = str(len(str(n)))
对于cProfile.run('foo(1000000)'),我没有提到必须拨打str的许多电话:
1000004 function calls in 1.163 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 1.163 1.163 <string>:1(<module>)
1 1.046 1.046 1.163 1.163 example.py:172(foo)
1000000 0.081 0.000 0.081 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.036 0.036 0.036 0.036 {range}
如何让cProfile.run 显示调用str 的统计信息?
【问题讨论】:
标签: python string python-2.7 profiling