You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

85 lines
1.7 KiB

  1. unit uutlTiming;
  2. { Package: Utils
  3. Prefix: utl - UTiLs
  4. Beschreibung: diese Unit enthält platformunabhängige Methoden für Zeitberechnungen und -messungen
  5. Mehr oder weniger platformunabhängige Timestampgenerierung.
  6. GetTickCount64 ms-Timer
  7. GetMicroTime us-Timer analog php microtime()
  8. Achtung: windows.pp deklariert auch eine GetTickCount64, wird gegen diese gelinkt
  9. läuft die exe nicht mehr unter XP. Unbeding uutlTiming *nach* windows einbinden. }
  10. {$mode objfpc}{$H+}
  11. interface
  12. uses
  13. Classes
  14. {$ifdef Windows}
  15. , Windows
  16. {$else}
  17. , Unix, BaseUnix
  18. {$endif};
  19. function GetTickCount64: QWord;
  20. function GetMicroTime: QWord;
  21. implementation
  22. {$IF defined(WINDOWS)}
  23. var
  24. PERF_FREQ: Int64;
  25. function GetTickCount64: QWord;
  26. begin
  27. // GetTickCount64 is better, but we need to check the Windows version to use it
  28. Result := Windows.GetTickCount();
  29. end;
  30. function GetMicroTime: QWord;
  31. var
  32. pc: Int64;
  33. begin
  34. pc := 0;
  35. QueryPerformanceCounter(pc);
  36. Result:= (pc * 1000*1000) div PERF_FREQ;
  37. end;
  38. initialization
  39. PERF_FREQ := 0;
  40. QueryPerformanceFrequency(PERF_FREQ);
  41. {$ELSEIF defined(UNIX)}
  42. function GetTickCount64: QWord;
  43. var
  44. tp: TTimeVal;
  45. begin
  46. fpgettimeofday(@tp, nil);
  47. Result := (Int64(tp.tv_sec) * 1000) + (tp.tv_usec div 1000);
  48. end;
  49. function GetMicroTime: QWord;
  50. var
  51. tp: TTimeVal;
  52. begin
  53. fpgettimeofday(@tp, nil);
  54. Result := (Int64(tp.tv_sec) * 1000*1000) + tp.tv_usec;
  55. end;
  56. {$ELSE}
  57. function GetTickCount64: QWord;
  58. begin
  59. Result := Trunc(Now * 24 * 60 * 60 * 1000);
  60. end;
  61. function GetMicroTime: QWord;
  62. begin
  63. Result := Trunc(Now * 24 * 60 * 60 * 1000*1000);
  64. end;
  65. {$ENDIF}
  66. end.