SpikeStream Library
0.2
|
00001 //SpikeStream includes 00002 #include "PerformanceTimer.h" 00003 using namespace spikestream; 00004 00005 //Other includes 00006 #include <iostream> 00007 using namespace std; 00008 00009 00011 PerformanceTimer::PerformanceTimer(){ 00012 timerStart = QDateTime::currentDateTime(); 00013 } 00014 00015 00017 PerformanceTimer::~PerformanceTimer(){ 00018 } 00019 00020 00021 /*----------------------------------------------------------*/ 00022 /*------ PUBLIC METHODS ------*/ 00023 /*----------------------------------------------------------*/ 00024 00026 void PerformanceTimer::start(){ 00027 timerStart = QDateTime::currentDateTime(); 00028 } 00029 00030 00032 void PerformanceTimer::printTime(const QString& taskName){ 00033 QDateTime currDateTime = QDateTime::currentDateTime(); 00034 00035 //Later in the same day, can just subtract the milliseconds 00036 if(timerStart.daysTo(currDateTime) == 0){ 00037 cout<<taskName.toStdString()<<" took "<<( timerStart.time().msecsTo(currDateTime.time()) )<<" ms."<<endl; 00038 } 00039 //1 day difference - still output result in milliseconds in case timing takes place over midnight 00040 else if (timerStart.daysTo(currDateTime) == 1){ 00041 //Calculate the time left in day1 00042 unsigned int msecDay1 = timerStart.time().hour()*3600000 + timerStart.time().minute()*60000 + timerStart.time().second()*1000 + timerStart.time().msec(); 00043 msecDay1 -= 86400000; 00044 00045 //Calculate msec elapsed in day2 00046 unsigned int msecDay2 = currDateTime.time().hour()*3600000 + currDateTime.time().minute()*60000 + currDateTime.time().second()*1000 + currDateTime.time().msec(); 00047 cout<<taskName.toStdString()<<" took "<<(msecDay1 + msecDay2)<<" ms."<<endl; 00048 } 00049 //More than 1 day difference - output result in seconds 00050 else{ 00051 cout<<taskName.toStdString()<<" took "<<( currDateTime.toTime_t() - timerStart.toTime_t() )<<" seconds."<<endl; 00052 } 00053 } 00054 00055