2013-04-19 02:52:48 +00:00
|
|
|
|
|
|
|
class timing_c
|
|
|
|
{
|
|
|
|
private:
|
2013-04-25 04:36:56 +00:00
|
|
|
int64_t start;
|
|
|
|
int64_t end;
|
2013-04-19 02:52:48 +00:00
|
|
|
|
|
|
|
int reset;
|
|
|
|
public:
|
|
|
|
timing_c(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Start()
|
|
|
|
{
|
2013-04-25 04:44:49 +00:00
|
|
|
#ifdef _MSVC_VER
|
2013-04-25 04:36:56 +00:00
|
|
|
const int64_t *s = &start;
|
2013-04-19 02:52:48 +00:00
|
|
|
__asm
|
|
|
|
{
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push edx
|
|
|
|
|
|
|
|
rdtsc
|
|
|
|
mov ebx, s
|
|
|
|
mov [ebx], eax
|
|
|
|
mov [ebx + 4], edx
|
|
|
|
|
|
|
|
pop edx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
}
|
2013-04-25 04:44:49 +00:00
|
|
|
#else
|
|
|
|
asm("rdtsc" : "=A"(start));
|
|
|
|
#endif
|
2013-04-19 02:52:48 +00:00
|
|
|
}
|
|
|
|
int End()
|
|
|
|
{
|
2013-04-25 04:36:56 +00:00
|
|
|
int64_t time;
|
2013-04-25 04:44:49 +00:00
|
|
|
#ifdef _MSVC_VER
|
|
|
|
const int64_t *e = &end;
|
2013-04-19 02:52:48 +00:00
|
|
|
__asm
|
|
|
|
{
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push edx
|
|
|
|
|
|
|
|
rdtsc
|
|
|
|
mov ebx, e
|
|
|
|
mov [ebx], eax
|
|
|
|
mov [ebx + 4], edx
|
|
|
|
|
|
|
|
pop edx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
}
|
2013-04-25 04:44:49 +00:00
|
|
|
#else
|
|
|
|
asm("rdtsc" : "=A"(time));
|
2013-04-19 02:52:48 +00:00
|
|
|
#endif
|
|
|
|
time = end - start;
|
|
|
|
if (time < 0)
|
|
|
|
{
|
|
|
|
time = 0;
|
|
|
|
}
|
|
|
|
return((int)time);
|
|
|
|
}
|
|
|
|
};
|
2013-04-25 04:36:56 +00:00
|
|
|
// end
|