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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
QElapsedTimeroverQTimeis that Qt will try to use the best available monotonic timer on each platform.QTimeis 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 aTimerobject, 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):