การใช้ high Resolution Timer ด้วย c++ 


การใช้ high Resolution Timer ด้วย c++




#include <windows.h>
#include <stdio.h>
#include <conio.h>

typedef struct {
LARGE_INTEGER start;
LARGE_INTEGER stop;
} stopWatch;

class CStopWatch {

private:
stopWatch timer;
LARGE_INTEGER frequency;
double LIToSecs( LARGE_INTEGER & L) ;
public:
CStopWatch() ;
void startTimer( ) ;
void stopTimer( ) ;
double getElapsedTime() ;
};
double CStopWatch::LIToSecs( LARGE_INTEGER & L) {
return ((double)L.QuadPart /(double)frequency.QuadPart) ;
}

CStopWatch::CStopWatch(){
timer.start.QuadPart=0;
timer.stop.QuadPart=0;
QueryPerformanceFrequency( &frequency ) ;
}

void CStopWatch::startTimer( ) {
QueryPerformanceCounter(&timer.start) ;
}

void CStopWatch::stopTimer( ) {
QueryPerformanceCounter(&timer.stop) ;
}

double CStopWatch::getElapsedTime() {
LARGE_INTEGER time;
time.QuadPart = timer.stop.QuadPart - timer.start.QuadPart;
return LIToSecs( time) ;
}

#define n 200000

int main(int argc, char*argv[])
{
int x[n];
int j= 0;
int k = 1;
int l = 0;
int m=0;
CStopWatch timer;
for(int k=1;k<n/2;k=k*2)
{
timer.startTimer();
for(int l=0;l<20;l++)
{

for(int i=0;i< k;i++)
{
m=i;
while(m<n)
{
//printf("%d ",m);
x[m] = 7*x[m]*x[m];
m = (m + k ) ;
}
}
}
timer.stopTimer();
printf("\nk= %d --> \t%lf\n\n",k,timer.getElapsedTime());
}



}



http://expert-programming-tutor.com/

[ view entry ] ( 2633 views )   |  permalink  |  $star_image$star_image$star_image$star_image$star_image ( 3 / 2115 )

<<First <Back | 1 | 2 | 3 | 4 | 5 | Next> Last>>