In my code, the execution time of my for loop is increasing by roughly 1 second after roughly 1000 iteration. So, I am suspecting, there is something wrong within my for loop. I have break point after 1000 iteration, but i need to know which line is taking more time. use of time.time()
while line-by-line debugging is certainly not a good idea. I could have used timeit
to get the exact execution time for a block of code but it also not a good idea for my case, because i need to get the execution time of each line within a for loop, but not the whole loop. In this case what should i do? I am using pycharm for debugging. is there any option in this editor?
Asked
Active
Viewed 4,104 times
0

sovon
- 877
- 2
- 12
- 28
-
Possible duplicate of [How can you profile a python script?](https://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script) – SH7890 Jun 16 '17 at 13:34
1 Answers
2
If you're using professional version of PyCharm, you can use builtin profiler.
Otherwise, refer to this answer. Alternatively, you can have a look at line_profiler.

grundic
- 4,641
- 3
- 31
- 47
-
Just run the program with pycharm's default cProfiler, but i can not sees anything that say excution time for a line. – sovon Jun 16 '17 at 16:16
-
On statistics page you can see what caused most load: how much time it was called and for how long. Otherwise, have a look at [line_profiler](https://github.com/rkern/line_profiler) or [memory_profiler](https://pypi.python.org/pypi/memory_profiler). – grundic Jun 16 '17 at 16:34