Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

It's often useful to be able to time code, for instance, to evaluate alternative approaches to the same problem. Because this is a thing I use frequently, I have created this Stopwatch templated class that I'd like for you all to review. Unlike some other recent code other recent code, this class is intended to be cross-platform and relies only on a working implementation of the std::chrono utilities in C++11.

It's often useful to be able to time code, for instance, to evaluate alternative approaches to the same problem. Because this is a thing I use frequently, I have created this Stopwatch templated class that I'd like for you all to review. Unlike some other recent code, this class is intended to be cross-platform and relies only on a working implementation of the std::chrono utilities in C++11.

It's often useful to be able to time code, for instance, to evaluate alternative approaches to the same problem. Because this is a thing I use frequently, I have created this Stopwatch templated class that I'd like for you all to review. Unlike some other recent code, this class is intended to be cross-platform and relies only on a working implementation of the std::chrono utilities in C++11.

added usage notes.
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284

A few words about usage

The goal was to create a minimal but complete interface. The constructor does nothing except calling start.

start sets both starting and ending times to the current underlying clock's now() and essentially functions as a reset (which was another name I considered for this function.)

elapsed does not modify the underlying Stopwatch and only returns the difference between the internally stored _end and _start.

stop returns the elapsed time between "now" and the internally stored _start and so can be used to measure several times all relative to the same start time.

restart does the same thing as stop except it also resets the start time.

A few words about usage

The goal was to create a minimal but complete interface. The constructor does nothing except calling start.

start sets both starting and ending times to the current underlying clock's now() and essentially functions as a reset (which was another name I considered for this function.)

elapsed does not modify the underlying Stopwatch and only returns the difference between the internally stored _end and _start.

stop returns the elapsed time between "now" and the internally stored _start and so can be used to measure several times all relative to the same start time.

restart does the same thing as stop except it also resets the start time.

edited tags
Link
200_success
  • 145.4k
  • 22
  • 190
  • 478
fixed code formatting in test driver
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
Loading
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /