我有一个在Linux上运行的C++应用程序,我正在优化它.如何确定代码的哪些区域运行缓慢?
项目欧拉和其他编码竞赛通常有最长的运行时间或人们吹嘘他们的特定解决方案运行的速度.使用python,有时候这些方法有点像kludgey - 即添加时间码__main__.
分析python程序运行多长时间的好方法是什么?
感谢来自这里的人们的帮助,我能够获得塔斯马尼亚骆驼拼图工作的代码.然而,它非常慢(我想.我不确定,因为这是我在Python中的第一个程序).在代码底部运行的示例需要很长时间才能在我的机器中解决:
dumrat@dumrat:~/programming/python$ time python camels.py
[['F', 'F', 'F', 'G', 'B', 'B', 'B'], ['F', 'F', 'G', 'F', 'B', 'B', 'B'],
['F', 'F', 'B', 'F', 'G', 'B', 'B'], ['F', 'F', 'B', 'F', 'B', 'G', 'B'],
['F', 'F', 'B', 'G', 'B', 'F', 'B'], ['F', 'G', 'B', 'F', 'B', 'F', 'B'],
['G', 'F', 'B', 'F', 'B', 'F', 'B'], ['B', 'F', 'G', 'F', 'B', 'F', 'B'],
['B', 'F', 'B', 'F', 'G', 'F', 'B'], ['B', 'F', 'B', 'F', 'B', 'F', 'G'],
['B', 'F', 'B', 'F', 'B', …Run Code Online (Sandbox Code Playgroud) 这是我的问题,因为我升级到OSX Lion:每当我在Django项目中更改文件时runserver重新加载,它需要一段时间再开始服务.
即使在新创建的Django 1.4项目中也会发生这种情况.虽然在Snow Leopard上没有这个问题.
我使用了cProfile,这是它花费大部分时间的地方:
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.001 0.001 48.068 48.068 manage.py:2(<module>)
1 0.000 0.000 48.033 48.033 __init__.py:431(execute_manager)
1 0.000 0.000 48.032 48.032 __init__.py:340(execute)
1 0.000 0.000 47.908 47.908 base.py:182(run_from_argv)
1 0.000 0.000 47.907 47.907 base.py:193(execute)
1 0.000 0.000 47.814 47.814 runserver.py:39(handle)
1 0.000 0.000 47.814 47.814 runserver.py:69(run)
1 0.001 0.001 47.814 47.814 autoreload.py:129(main)
1 0.000 0.000 47.813 47.813 autoreload.py:107(python_reloader)
1 0.000 0.000 47.813 47.813 autoreload.py:96(restart_with_reloader)
1 0.000 0.000 47.813 …Run Code Online (Sandbox Code Playgroud)