我正在打电话argon2 https://en.wikipedia.org/wiki/Argon2- Qt 中的内存密集型哈希函数并测量其运行时间:
...
QTime start = QTime::currentTime();
// call hashing function
QTime finish = QTime::currentTime();
time = start.msecsTo(finish) / 1000.0;
...
在 argon2 库的测试用例中,时间以另一种方式测量:
...
clock_t start = clock();
// call hashing function
clock_t finish = clock();
time = ((double)finish - start) / CLOCKS_PER_SEC;
...
我正在按照他们在测试用例中调用的方式调用该函数。但我得到的数字是两倍大(慢两倍)。为什么?如何测量Qt中函数的运行时间? Clock() 实际测量什么?
env:virtualBox、Ubuntu14.04 64位、Qt5.2.1、Qt Creator 3.0.1。
您还可以尝试使用 QElapsedTimer:
QElapsedTimer timer;
timer.start();
slowOperation1();
qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";
qDebug() << "The slow operation took" << timer.nsecsElapsed() << "nanoseconds";
QElapsed 计时器的文档 http://doc.qt.io/qt-4.8/qelapsedtimer.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)