1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| // file timer.h
// ********************************************************
// Timer class: For test perform
// ********************************************************
// On the STMicro platform, the time returned by GetTickCount
// includes a ~0.014% time drift, which is by design. This
// translates to a time lag of approximately 1s every 2h.
// The time will wrap around to zero if the system is run
// continuously for 49.7 days. msdn source.
#ifndef _TIMER_H_
#define _TIMER_H_
#define MAX_SAUV 100
#include <windows.h>
class Timer
{
public:
Timer()
{ for(int i = 0;i<MAX_SAUV;i++)
{
sauv[i]=0;
}
}
double T_Time(void)
{
return ((double)GetTickCount());
}
void T_Start(int i)
{ if(i<MAX_SAUV)
sauv[i]=GetTickCount();
}
double T_Stop(int i)
{
if(i<MAX_SAUV)
return ((double)(GetTickCount()-sauv[i]));
return 0;
}
DWORD sauv[MAX_SAUV];
};
#endif
/*************************************************
Et voici donc le main qui suit pour tester le dit timer:
int main()
{
Timer t;
double t1,t2,t3,t4;
t.T_Start(1);
Sleep(5);
t1=t.T_Stop(1);
t.T_Start(2);
Sleep(10);
t2=t.T_Stop(2);
t.T_Start(3);
Sleep(100);
t3=t.T_Stop(3);
t.T_Start(4);
Sleep(1000);
t4=t.T_Stop(4);
std::cout<<"Time: T1:"<<t1<<"ms T2:"<<t2<<"ms T3:"<<t3<<"ms T4:"<<t4<<"ms"<<std::endl;
return 0;
} |
Partager