Search code examples
pythonpycharm

How do I time script execution time in PyCharm without adding code every time?


Currently I just add the following lines around my code:

import time
start_time = time.time()

# my code here

print "time elapsed: {:.2f}s".format(time.time() - start_time)

Is it possible to achieve the same without adding code to every script I want to time? Either adding something in run configuration or using a plugin?


Solution

  • You can profile your script by hitting the 'profile' button (it is to the right of the 'run', 'debug', and 'run with coverage' buttons):

    Profile button

    Among the output, you will find the name of the script itself, and the time needed to run it.

    Note: the function is available in PyCharm PROFESSIONAL 2017.1 for the Linux platform; other installations might not provide the profiler button.