xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Go to the documentation of this file.
1 #pragma once
5 #include <string>
6 #include "../object.h"
7 #include "../ticks.h"
10 namespace xtd {
12  namespace diagnostics {
27  class stopwatch : public object{
28  public:
35  stopwatch() = default;
38  stopwatch(const stopwatch&) = default;
39  stopwatch& operator=(const stopwatch&) = default;
44  static int64_t frequency();
50  static bool is_high_resolution();
62  std::chrono::nanoseconds elapsed() const;
72  int64_t elapsed_milliseconds() const;
79  int64_t elapsed_nanoseconds() const;
89  int64_t elapsed_ticks() const;
94  bool is_running() const;
98  static int64_t get_timestamp();
102  void reset();
106  void restart();
115  void start();
122  static stopwatch start_new();
131  void stop();
133  private:
134  explicit stopwatch(bool start);
135  bool running_ = false;
136  int64_t start_ = 0;
137  int64_t stop_ = 0;
138  };
139  }
140 }
void start()
Starts, or resumes, measuring elapsed time for an interval.
int64_t elapsed_ticks() const
Gets the total elapsed time measured by the current instance, in timer ticks.
Initializes a new instance of the xtd::diagnostics::stopwatch class.
static stopwatch start_new()
Initializes a new xtd::diagnostics::stopwatch instance, sets the xtd::diagnostics::stopwatch::elapsed...
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
static int64_t get_timestamp()
Gets the current number of nanoseconds in the timer mechanism.
Provides a set of methods and properties that you can use to accurately measure elapsed time...
Definition: stopwatch.h:27
std::chrono::nanoseconds elapsed() const
Gets the total elapsed time measured by the current instance.
static bool is_high_resolution()
Indicates whether the timer is based on a high-resolution performance counter. This field is read-onl...
int64_t elapsed_milliseconds() const
Gets the total elapsed time measured by the current instance, in milliseconds.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:26
void stop()
Stops measuring elapsed time for an interval.
static int64_t frequency()
Gets the frequency of the timer as the number of nanoseconds per second. This field is read-only...
void reset()
Stops time interval measurement and resets the elapsed time to zero.
int64_t elapsed_nanoseconds() const
Gets the total elapsed time measured by the current instance, in nanoseconds.
void restart()
stops time interval measurement, resets the elapsed time to zero, and starts measuring elapsed time...
bool is_running() const
Gets a value indicating whether the stopwatch timer is running.