I am new to C++ , I have a program in C++ written for Linux. I\'m trying to convert it to Windows. The code I have is:
struct Timer
{
struct tms t[2];
Here's a class I wrote that I always use
#ifndef HIGHPERFTIMER_H
#define HIGHPERFTIMER_H
#include
#include
class StopWatch
{
LARGE_INTEGER freq, startTime, endTime, thisTime, lastTime ;
double fFreq ;
public:
double total_time ;
StopWatch()
{
QueryPerformanceFrequency( &freq ) ;
fFreq = (double)freq.QuadPart ;
total_time = 0 ;
printf( " --- The ffreq is %lf\n", fFreq ) ;
}
void start()
{
QueryPerformanceCounter( &startTime ) ;
thisTime = lastTime = startTime ;
total_time = 0.0 ; // start counter at 0 seconds
}
double stop()
{
QueryPerformanceCounter( &endTime ) ;
total_time = ( endTime.QuadPart - startTime.QuadPart ) / fFreq ;
return total_time ;
}
void update()
{
lastTime = thisTime ;
QueryPerformanceCounter( &thisTime ) ;
total_time += ( thisTime.QuadPart - lastTime.QuadPart ) / fFreq ;
}
} ;
#endif //HIGHPERFTIMER_H
Example usage:
int main()
{
StopWatch stopWatch ;
stopWatch.start() ;
///.. code..
stopWatch.stop() ;
printf( "Time elapsed: %f sec", stopWatch.total_time ) ;
}