Is there a simply way to knowing how much time consume each test case in QT Test Framework for C++?
It will be incredible helpful to getting some metrics.
Is there a simply way to knowing how much time consume each test case in QT Test Framework for C++?
It will be incredible helpful to getting some metrics.
time_t t = time(0);
will define a time variable in milliseconds since the epoch, and set it to the current moment. Fire one of these off before testing, one after testing, and compare the two to get how long the test took. As cbamber85 noted, it varies based on a number of things, so if you want your metrics to mean anything, you need to keep your platform stable (and even then they'll only be significant as a relative thing) but it's at least somethign you can work with.
You could write a custom Timer class which starts a usually monotonic elapsed timer on creation and prints the elapsed time on deletion (see
QElapsedTimer::elapsed()
):timer.h:
The benefit of using
QElapsedTimer
overQTime
is that Qt will try to use the best available monotonic timer on each platform.QTime
is not guaranteed to be montonic: it will decrease when time synchronization daemon/service adjusts the clock, etc.Now insert the line
Timer t;
at the beginning of each test case you want to measure the time of; no more code. This simply creates aTimer
object, which starts the internal timer, and deletes the object when it gets out of scope (which is at the end of the method) and thus prints the elapsed time:Your test case (.cpp):