如何在Qt中测量功能运行时间? [英] How to measure function running time in Qt?
本文介绍了如何在Qt中测量功能运行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在调用 argon2 -Qt中的内存密集型哈希函数,并测量其运行时间:
I am calling argon2 - memory intensive hashing function in Qt and measuring its running time:
...
QTime start = QTime::currentTime();
// call hashing function
QTime finish = QTime::currentTime();
time = start.msecsTo(finish) / 1000.0;
...
在argon2库的测试案例中,时间是用另一种方式测量的: / p>
In argon2 library's test case, time is measured in another way:
...
clock_t start = clock();
// call hashing function
clock_t finish = clock();
time = ((double)finish - start) / CLOCKS_PER_SEC;
...
我正在完全按照他们在测试用例中调用的方式来调用该函数。但是我得到的数字要大两倍(慢两倍)。为什么?如何在Qt中测量功能运行时间?
I am calling the function exactly as they call in their test case. But I am getting a twice bigger number (twice slower). Why? How to measure function running time in Qt? What clock() actually measures?
env :virtualBox,Ubuntu14.04 64bit,Qt5.2.1,Qt Creator 3.0.1。
env:virtualBox, Ubuntu14.04 64bit, Qt5.2.1, Qt Creator 3.0.1.
推荐答案
您还可以尝试使用QElapsedTimer:
You could also try to use the QElapsedTimer:
QElapsedTimer timer;
timer.start();
slowOperation1();
qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";
qDebug() << "The slow operation took" << timer.nsecsElapsed() << "nanoseconds";
这篇关于如何在Qt中测量功能运行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文