stopwatch.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: stopwatch.h
  3. // Purpose: interface of wxStopWatch
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxStopWatch
  9. The wxStopWatch class allow you to measure time intervals.
  10. For example, you may use it to measure the time elapsed by some function:
  11. @code
  12. wxStopWatch sw;
  13. CallLongRunningFunction();
  14. wxLogMessage("The long running function took %ldms to execute",
  15. sw.Time());
  16. sw.Pause();
  17. ... stopwatch is stopped now ...
  18. sw.Resume();
  19. CallLongRunningFunction();
  20. wxLogMessage("And calling it twice took $ldms in all", sw.Time());
  21. @endcode
  22. Since wxWidgets 2.9.3 this class uses @c QueryPerformanceCounter()
  23. function under MSW to measure the elapsed time. It provides higher
  24. precision than the usual timer functions but can suffer from bugs in its
  25. implementation in some Windows XP versions. If you encounter such problems,
  26. installing a Microsoft hot fix from http://support.microsoft.com/?id=896256
  27. could be necessary.
  28. @library{wxbase}
  29. @category{misc}
  30. @see wxTimer
  31. */
  32. class wxStopWatch
  33. {
  34. public:
  35. /**
  36. Constructor. This starts the stop watch.
  37. */
  38. wxStopWatch();
  39. /**
  40. Pauses the stop watch. Call Resume() to resume time measuring again.
  41. If this method is called several times, @c Resume() must be called the same
  42. number of times to really resume the stop watch. You may, however, call
  43. Start() to resume it unconditionally.
  44. */
  45. void Pause();
  46. /**
  47. Resumes the stop watch which had been paused with Pause().
  48. */
  49. void Resume();
  50. /**
  51. (Re)starts the stop watch with a given initial value.
  52. The stopwatch will always be running after calling Start(), even if
  53. Pause() had been called before and even if it had been called multiple
  54. times.
  55. */
  56. void Start(long milliseconds = 0);
  57. /**
  58. Returns the time in milliseconds since the start (or restart) or the last
  59. call of Pause().
  60. @see TimeInMicro()
  61. */
  62. long Time() const;
  63. /**
  64. Returns elapsed time in microseconds.
  65. This method is similar to Time() but returns the elapsed time in
  66. microseconds and not milliseconds. Notice that not all platforms really
  67. can measure times with this precision.
  68. @since 2.9.3
  69. */
  70. wxLongLong TimeInMicro() const;
  71. };