Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am working on QGIS. I need to determine how much time QGIS needed to finish a specific task. I have been unable to get execution times for the processes. What is the proper way to get processing time under QGIS?

share|improve this question
2  
What kind of task? –  Nathan W Nov 28 '12 at 5:52
add comment

2 Answers 2

What kind of tasks are you referring to?

I use the following static class to benchmark my code.

I designed it to be static so that I can call the start/stop/show methods wherever is needed without worrying about passing references to the Timer back and forth.

The optional parameters allow me to have several running at once, any values will do but names look nicer.

Sometimes its necessary to create a stub method and connect it to a signal in order to call these methods at the right moment, but without knowing more about what you are timing its hard to be specific.

from PyQt4.QtGui import *
from datetime import datetime

class Timer():
  startTimes=dict()
  stopTimes=dict()

  @staticmethod
  def start(key = 0):
    Timer.startTimes[key] = datetime.now()
    Timer.stopTimes[key] = None

  @staticmethod
  def stop(key = 0):
    Timer.stopTimes[key] = datetime.now()

  @staticmethod
  def show(key = 0):
    if key in Timer.startTimes:
      if Timer.startTimes[key] is not None:
        if key in Timer.stopTimes:
          if Timer.stopTimes[key] is not None:
            delta = Timer.stopTimes[key] - Timer.startTimes[key]
            QMessageBox.information(None,"Timer: " + str(key), str(delta))
share|improve this answer
    
A class with all staticmethods is normally considered bad practice. Just have a timer.py file and have these method as first class, also startTimes can be startTimes = [] –  Nathan W Nov 28 '12 at 8:34
    
Point taken, but I wasn't really fussed about best practice when coding this it is very ephemeral in nature. I use it to compare relative performance of alternative implementations and then remove it from the project once a decision is made. startTimes is a dict so I can use strings as keys and provide readable names. –  Kelly Thomas Nov 28 '12 at 9:00
    
opps yeah I meant startTimes = {} which is the same as dict(), sorry about that –  Nathan W Nov 28 '12 at 9:05
add comment

you can use python timeit function for testing it.

import timeit

def myfunction():
    try:
       #do something
    except AttributeError:
       pass

print timeit.timeit('testfunc(), 'from __main__ import myfunction as testfunc')

>>0.34454334343 

i hope it helps you....

share|improve this answer
    
Thank You for your help. I am working with big datasets, I need to know how long took to process a simple function (i.e. select by location). I know that can be done with python, but I was trying to call a log/ report function. Thanks!!! –  user13164 Nov 28 '12 at 15:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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