jedi-academy/codemp/qcommon/timing.h

68 lines
720 B
C
Raw Normal View History

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()
{
#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
}
#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;
#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
}
#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