timing.h 663 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. class timing_c
  2. {
  3. private:
  4. __int64 start;
  5. __int64 end;
  6. int reset;
  7. public:
  8. timing_c(void)
  9. {
  10. }
  11. void Start()
  12. {
  13. const __int64 *s = &start;
  14. __asm
  15. {
  16. push eax
  17. push ebx
  18. push edx
  19. rdtsc
  20. mov ebx, s
  21. mov [ebx], eax
  22. mov [ebx + 4], edx
  23. pop edx
  24. pop ebx
  25. pop eax
  26. }
  27. }
  28. int End()
  29. {
  30. const __int64 *e = &end;
  31. __int64 time;
  32. __asm
  33. {
  34. push eax
  35. push ebx
  36. push edx
  37. rdtsc
  38. mov ebx, e
  39. mov [ebx], eax
  40. mov [ebx + 4], edx
  41. pop edx
  42. pop ebx
  43. pop eax
  44. }
  45. time = end - start;
  46. if (time < 0)
  47. {
  48. time = 0;
  49. }
  50. return((int)time);
  51. }
  52. };
  53. // end