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