AsphyrePrfl.pas
上传用户:ctlcnc
上传日期:2021-12-10
资源大小:4933k
文件大小:2k
源码类别:

2D图形编程

开发平台:

Delphi

  1. unit AsphyrePrfl;
  2. //---------------------------------------------------------------------------
  3. interface
  4. //---------------------------------------------------------------------------
  5. uses
  6.  Windows, SysUtils;
  7. //---------------------------------------------------------------------------
  8. procedure BeginMeasure();
  9. procedure EndMeasure();
  10. function GetMeasure(): Single;
  11. function GetMeasureFPS(): Single;
  12. function MeasureText(): string;
  13. function MeasureFPSText(): string;
  14. //---------------------------------------------------------------------------
  15. implementation
  16. //---------------------------------------------------------------------------
  17. const
  18.  SampleCount = 120;
  19. //---------------------------------------------------------------------------
  20. var
  21.  Freq, InitTime, EndTime: Int64;
  22.  Elapsed: Single;
  23.  ElapsedAvg: array[0..SampleCount - 1] of Single;
  24. //---------------------------------------------------------------------------
  25. procedure BeginMeasure();
  26. begin
  27.  QueryPerformanceFrequency(Freq);
  28.  QueryPerformanceCounter(InitTime);
  29. end;
  30. //---------------------------------------------------------------------------
  31. procedure EndMeasure();
  32. var
  33.  Taken: Single;
  34.  i: Integer;
  35. begin
  36.  QueryPerformanceCounter(EndTime);
  37.  Taken:= 1000.0 * (EndTime - InitTime) / Freq;
  38.  for i:= 0 to SampleCount - 2 do
  39.   ElapsedAvg[i]:= ElapsedAvg[i + 1];
  40.  ElapsedAvg[SampleCount - 1]:= Taken;
  41.  Elapsed:= 0.0;
  42.  for i:= 0 to SampleCount - 1 do
  43.   Elapsed:= Elapsed + ElapsedAvg[i];
  44.  Elapsed:= Elapsed / SampleCount;
  45. end;
  46. //---------------------------------------------------------------------------
  47. function GetMeasure(): Single;
  48. begin
  49.  Result:= Elapsed;
  50. end;
  51. //---------------------------------------------------------------------------
  52. function GetMeasureFPS(): Single;
  53. begin
  54.  if (Elapsed <> 0.0) then Result:= 1000.0 / Elapsed
  55.   else Result:= 0.0;
  56. end;
  57. //---------------------------------------------------------------------------
  58. function MeasureText(): string;
  59. begin
  60.  Result:= Format('%1.1f', [Elapsed]);
  61. end;
  62. //---------------------------------------------------------------------------
  63. function MeasureFPSText(): string;
  64. begin
  65.  Result:= IntToStr(Round(GetMeasureFPS()));
  66. end;
  67. //---------------------------------------------------------------------------
  68. end.