I want to know how much time does my function take,so that I can compare and choose the better one.
Is there an easy way to do this?I don't want unit test thing,that seems like a bit overkill.
I want to know how much time does my function take,so that I can compare and choose the better one.
Is there an easy way to do this?I don't want unit test thing,that seems like a bit overkill.
It's not the goodbye that hurts,but the flashback that follow.
It depends what reliability of such measurement you require.
The easiest way is:
but it is completely unreliable, especially if your function is short. Much better is to use QBENCHMARK from QtTestLib (I don't think it is an overkill).Qt Code:
QTime t; t.start(); functionCall(); qDebug() << t.elapsed() << "ms";To copy to clipboard, switch view to plain text mode
MorrisLiang (12th June 2010), Zlatomir (12th June 2010)
I tried QBENCHMARK today,but with no luck.
Qt Code:
public slots: void testUpdateContents() { QBENCHMARK { updateContents(); } }To copy to clipboard, switch view to plain text mode
In one of my class, there's a slot called testUpdateContents().It's connected to a QPushButton's clicked() SIGNAL.It complied without any error.
But when I clicked that button,I got "Segmentation fault".
The attachment shows where's the line of code causing the problem.
It's not the goodbye that hurts,but the flashback that follow.
What does updateContents() do? By the way, QBENCHMARK should be used in tests, not in regular apps.
It's not the goodbye that hurts,but the flashback that follow.
If what the function does is that it schedules some events (i.e. by calling update() on widgets) then measuring the time it takes to finish the updateContents() function doesn't yield any practical value as most work is done already after that function returns (in the event loop).
Bookmarks