xtd 0.2.0
Loading...
Searching...
No Matches
stopwatch.hpp
Go to the documentation of this file.
1
4#pragma once
5#include <string>
6#include "../object.hpp"
7#include "../time_span.hpp"
8
10namespace xtd {
12 namespace diagnostics {
37 public:
39
47 stopwatch() = default;
49
51 stopwatch(const xtd::diagnostics::stopwatch&) = default;
52 auto operator =(const xtd::diagnostics::stopwatch&) -> stopwatch& = default;
54
56
68 [[nodiscard]] auto elapsed() const noexcept -> xtd::time_span;
69
78 [[nodiscard]] auto elapsed_milliseconds() const noexcept -> xtd::int64;
79
85 [[nodiscard]] auto elapsed_nanoseconds() const noexcept -> xtd::int64;
86
95 [[nodiscard]] auto elapsed_ticks() const noexcept -> xtd::int64;
96
100 [[nodiscard]] auto is_running() const noexcept -> bool;
102
104
108 [[nodiscard]] static auto frequency() noexcept -> xtd::int64;
109
114 [[nodiscard]] static auto is_high_resolution() noexcept -> bool;
116
118
122 auto reset() noexcept -> void;
123
126 auto restart() noexcept -> void;
127
135 auto start() noexcept -> void;
136
142 [[nodiscard]] static auto start_new() noexcept -> xtd::diagnostics::stopwatch;
143
151 auto stop() noexcept -> void;
153
155
159 [[nodiscard]] static auto get_timestamp() noexcept -> std::chrono::nanoseconds;
160
163 [[nodiscard]] static auto get_timestamp_milliseconds() noexcept -> xtd::int64;
164
167 [[nodiscard]] static auto get_timestamp_nanoseconds() noexcept -> xtd::int64;
168
171 [[nodiscard]] static auto get_timestamp_ticks() noexcept -> xtd::int64;
173
174 private:
175 explicit stopwatch(bool start);
176 bool running_ = false;
177 xtd::int64 start_ = 0;
178 xtd::int64 stop_ = 0;
179 };
180 }
181}
Provides a set of methods and properties that you can use to accurately measure elapsed time.
Definition stopwatch.hpp:36
static auto get_timestamp() noexcept -> std::chrono::nanoseconds
Gets the current number of nanoseconds in the timer mechanism.
auto reset() noexcept -> void
Stops time interval measurement and resets the elapsed time to zero.
auto is_running() const noexcept -> bool
Gets a value indicating whether the stopwatch timer is running.
auto start() noexcept -> void
Starts, or resumes, measuring elapsed time for an interval.
auto elapsed_ticks() const noexcept -> xtd::int64
Gets the total elapsed time measured by the current instance, in timer ticks.
static auto get_timestamp_milliseconds() noexcept -> xtd::int64
Gets the current number of nanoseconds in the timer mechanism, in milliseconds.
stopwatch()=default
Initializes a new instance of the xtd::diagnostics::stopwatch class.
auto elapsed() const noexcept -> xtd::time_span
Gets the total elapsed time measured by the current instance.
auto stop() noexcept -> void
Stops measuring elapsed time for an interval.
static auto get_timestamp_nanoseconds() noexcept -> xtd::int64
Gets the current number of nanoseconds in the timer mechanism, in nanoseconds.
auto elapsed_milliseconds() const noexcept -> xtd::int64
Gets the total elapsed time measured by the current instance, in milliseconds.
static auto is_high_resolution() noexcept -> bool
Indicates whether the timer is based on a high-resolution performance counter. This field is read-onl...
auto elapsed_nanoseconds() const noexcept -> xtd::int64
Gets the total elapsed time measured by the current instance, in nanoseconds.
static auto frequency() noexcept -> xtd::int64
Gets the frequency of the timer as the number of nanoseconds per second. This field is read-only.
static auto get_timestamp_ticks() noexcept -> xtd::int64
Gets the current number of nanoseconds in the timer mechanism, in ticks.
auto restart() noexcept -> void
stops time interval measurement, resets the elapsed time to zero, and starts measuring elapsed time.
static auto start_new() noexcept -> xtd::diagnostics::stopwatch
Initializes a new xtd::diagnostics::stopwatch instance, sets the xtd::diagnostics::stopwatch::elapsed...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Represents a time interval.
Definition time_span.hpp:29
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::object class.
Contains xtd::time_span class.