Nir
Nir

Reputation: 914

QProcess execution time

I would like to measure execution time of a QProcess object.

Is there an internal attribute, method or object in PySide for execution time measurements?

The current approach is to measure it from the outside using time.time().

Example code:

from PySide import QtCore
import time

p = QtCore.QProcess()
start_time = time.time()
p.start('ping -n 5 127.0.0.1 >nul')
p.waitForFinished(-1)
end_time = time.time() - start_time

print(end_time)

Upvotes: 2

Views: 663

Answers (1)

Tom Myddeltyn
Tom Myddeltyn

Reputation: 1375

One way you could do this is as follows. This uses the systems time command to get the time of execution.

from PySide import QtCore
import time

p = QtCore.QProcess()
p.start('time -p ping -n 5 127.0.0.1 >nul')
p.waitForFinished(-1)
stdOut = p.readAllStandardOutput()
print(stdOut)
#TODO you will have to regex the stdOut to get the values you want.

Here is another approach:

from PySide import QtCore
import time

timer = QtCore.QTime()


def handle_proc_stop(*vargs):
    procTime = timer.elapsed()
    print("Process took {} miliseconds".format(procTime))

p = QtCore.QProcess()
p.started.connect(timer.start)
p.finished.connect(handle_proc_stop)
p.start('ping -n 5 127.0.0.1 >nul')
p.waitForFinished(-1)

Upvotes: 1

Related Questions