[Qt-interest] how to computing costed time of a function?

Christopher Rasch-Olsen Raa christopher at technophile.info
Thu Jul 16 10:56:09 CEST 2009


Torsdag 16 juli 2009 08:22:06 skrev James Yan :
> with windows API, i can :
>
> ===
> LARGE_INTEGER  feq,t_start,t_end;
> int                         cost_time;
>
> QueryPerformanceFrequency(&feq);
>
> QueryPerformanceCounter(&t_start);
> something_cost_time();
> QueryPerformanceCounter(&t_end);
>
> cost_time = (int)((t_end.QuadPart-t_start.QuadPart)*1000/feq.QuadPart);===
>
> how to with Qt? can archive the same granularity?  thanks.

Hi,

You could use QTime for such measurement. Have a look at QTime::start().
QTime timer;
timer.start();
long_operation();
qDebug() << "Elapsed:" << timer.elapsed();

You could also have a look at Valgrind, more specifically callgrind. Lots of 
useful information there. By using callgrind with kcachegrind you can get 
pretty awesome information about what you application is doing.

--
Christopher



More information about the Qt-interest-old mailing list