Source code of Windows XP (NT5)
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.

101 lines
2.3 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: stopwtch.cxx
  7. //
  8. // Contents: StopWatch timer
  9. //
  10. // Classes: CStopWatch
  11. //
  12. // Functions:
  13. //
  14. // History: 30-June-93 t-martig Created
  15. //
  16. //--------------------------------------------------------------------------
  17. extern "C"
  18. {
  19. #include <nt.h>
  20. #include <ntrtl.h>
  21. #include <nturtl.h>
  22. };
  23. #include <windows.h>
  24. #include <stopwtch.hxx>
  25. //+-------------------------------------------------------------------
  26. //
  27. // Member: CStopWatch::Resolution, public
  28. //
  29. // Synopsis: Inquires performance timer resolution
  30. //
  31. // Returns: Performance counter ticks / second
  32. //
  33. // History: 30-June-93 t-martig Created
  34. //
  35. //--------------------------------------------------------------------
  36. CStopWatch::CStopWatch ()
  37. {
  38. QueryPerformanceFrequency (&liFreq);
  39. }
  40. //+-------------------------------------------------------------------
  41. //
  42. // Member: CStopWatch::Reset, public
  43. //
  44. // Synopsis: Starts measurement cycle
  45. //
  46. // History: 30-June-93 t-martig Created
  47. //
  48. //--------------------------------------------------------------------
  49. void CStopWatch::Reset ()
  50. {
  51. QueryPerformanceCounter (&liStart); // BUGBUG - test for error !
  52. }
  53. //+-------------------------------------------------------------------
  54. //
  55. // Member: CStopWatch::Read, public
  56. //
  57. // Synopsis: Reads stop watch timer
  58. //
  59. // Returns: Time since call of CStopWatch::Reset (in microseconds)
  60. //
  61. // History: 30-June-93 t-martig Created
  62. //
  63. //--------------------------------------------------------------------
  64. ULONG CStopWatch::Read ()
  65. {
  66. LARGE_INTEGER liNow, liDelta, liRemainder;
  67. QueryPerformanceCounter (&liNow); // BUGBUG - test for error
  68. liDelta = RtlLargeIntegerSubtract (liNow, liStart);
  69. liDelta = RtlExtendedIntegerMultiply (liDelta, 1000000);
  70. liDelta = RtlLargeIntegerDivide (liDelta, liFreq, &liRemainder);
  71. return liDelta.LowPart;
  72. }
  73. //+-------------------------------------------------------------------
  74. //
  75. // Member: CStopWatch::Resolution, public
  76. //
  77. // Synopsis: Inquires performance timer resolution
  78. //
  79. // Returns: Performance counter ticks / second
  80. //
  81. // History: 30-June-93 t-martig Created
  82. //
  83. //--------------------------------------------------------------------
  84. ULONG CStopWatch::Resolution ()
  85. {
  86. return liFreq.LowPart;
  87. }