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?
-
Possible duplicate of How can you profile a python script?SH7890– SH78902017-06-16 13:34:24 +00:00Commented Jun 16, 2017 at 13:34
Add a comment
|
1 Answer
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.
2 Comments
sovon
Just run the program with pycharm's default cProfiler, but i can not sees anything that say excution time for a line.
grundic
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 or memory_profiler.