$start = microtime(1);$time = microtime(1) - $start;
C++ (Qt)QElapsedTimer timer;timer.start();
C++ (Qt)qDebug() << timer.elapsed();
C++ (Qt)qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";qDebug() << "The slow operation took" << timer.elapsed()/1000 << "seconds";qDebug() << "The slow operation took" << timer.elapsed()/1000/60 << "minutes";
C++ (Qt)#include <QtCore/QCoreApplication>#include <QElapsedTimer>#include <Windows.h> int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QElapsedTimer t; t.start(); qDebug("%d", t.elapsed()); Sleep(10000); qDebug("%d", t.elapsed()); return a.exec();}
C++ (Qt)class MyClass : public QObject{ ...public slots: void slot1() { timer.start(); } void slot2() { qint64 res = timer.elapsed(); qDebug() << "The slow operation took" << res << "milliseconds"; qDebug() << "The slow operation took" << res/1000 << "seconds"; qDebug() << "The slow operation took" << res/1000/60 << "minutes"; } private: QElapsedTimer timer;};