4

I would like to be able to log execution times of the algorithms launched in the toolbox. I see there's a history of all the launched commands with start times but there is nothing given about the duration of the process.

Is there a way to achieve that ?

  • 1
    Do you mean algorithms launched as scripts or from the GUI? – mgri May 25 '17 at 14:47
  • Those launched from the GUI in the "processing toolbox". – snaileater May 25 '17 at 14:49
  • Not sure if it's currently possible via a GUI option but if from scripts as @mgri mentioned then you could certainly use the timeit module. – Joseph May 25 '17 at 14:52
  • I see there's a post execution script option in the toolbox preferences. Is there a way to retrieve the last executed algorithm and any related information about it using a custom python script ? – snaileater May 25 '17 at 14:57
  • @snaileater any feedback? – mgri May 29 '17 at 6:41
4

Following your suggestion about post execution scripts, a raw idea for knowing the execution time is explained in the following.


Step 1

Copy-and-paste this code in any text editor and save it as a new file with the .py extension:

from datetime import datetime
print datetime.now()

Step 2

Go to Processing >> General and set it both in Post-execution script and Pre-execution script options (and then click the OK button). When needed, the above code will print the current datetime in the Python Console.

Step 3

Run the algorithm you want from the Processing Toolbox; you should get two datetimes, one at the start and one at the end of the analysis, like these:

2017-05-25 18:14:46.180000 # this is the start time
2017-05-25 18:26:10.420000 # this is the end time

Step 4

Run the following code from the Python Console (you only need to manually copy-and-paste the execution times you get printed in the Python Console):

from datetime import datetime
start_time = '18:14:46.180000' # add here the start time
end_time = '18:26:10.420000' # add here the end time
def_format = '%H:%M:%S.%f'
duration = datetime.strptime(end_time, def_format) - datetime.strptime(start_time, def_format)
print duration

This will print the duration of the analysis:

0:11:24.240000 # this is the duration of the analysis

Even if it is a little uncomfortable, it allows evaluating the exact execution time also when the analysis requires much time and you can't wait until it is finished.

Obviously, this approach is thought for algorithms executed from the GUI; using PyQGIS, instead, the whole process would be a lot easier and simpler to accomplish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.