micro-test-plus
6.0.0
µTest++ Testing Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
stopwatch-inlines.h
Go to the documentation of this file.
1
// ----------------------------------------------------------------------------
2
/*
3
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
4
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
5
*
6
* Permission to use, copy, modify, and/or distribute this software for any
7
* purpose is hereby granted, under the terms of the MIT license.
8
*
9
* If a copy of the license was not distributed with this file, it can be
10
* obtained from https://opensource.org/licenses/mit.
11
*/
12
13
// ----------------------------------------------------------------------------
14
32
33
#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_STOPWATCH_INLINES_H_
34
#define MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_STOPWATCH_INLINES_H_
35
36
// ----------------------------------------------------------------------------
37
38
#if defined(__cplusplus)
39
40
// ----------------------------------------------------------------------------
41
42
#if defined(__GNUC__)
43
#pragma GCC diagnostic push
44
45
#pragma GCC diagnostic ignored "-Waggregate-return"
46
#if defined(__clang__)
47
#pragma clang diagnostic ignored "-Wc++98-compat"
48
#pragma clang diagnostic ignored "-Wpre-c++17-compat"
49
#endif
// defined(__clang__)
50
#endif
// defined(__GNUC__)
51
52
// ============================================================================
53
54
namespace
micro_os_plus::micro_test_plus::detail
55
{
56
// ==========================================================================
57
63
inline
bool
64
stopwatch::has_elapsed
(
void
)
const
noexcept
65
{
66
return
is_recorded
(
start_time_
) &&
is_recorded
(
stop_time_
);
67
}
68
74
inline
bool
75
stopwatch::is_recorded
(
const
timespec& ts)
noexcept
76
{
77
return
ts.tv_sec != 0 || ts.tv_nsec != 0;
78
}
79
80
// --------------------------------------------------------------------------
81
82
#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
88
// Deprecated since 6.0.0; use has_elapsed().
89
inline
bool
90
stopwatch::has_begin
(
void
)
const
noexcept
91
{
92
return
is_recorded
(
start_time_
);
93
}
94
100
// Deprecated since 6.0.0; use has_elapsed().
101
inline
bool
102
stopwatch::has_end
(
void
)
const
noexcept
103
{
104
return
is_recorded
(
stop_time_
);
105
}
106
111
// Deprecated since 6.0.0; use has_elapsed().
112
inline
bool
113
stopwatch::has_timestamps
(
void
)
const
noexcept
114
{
115
return
has_elapsed
();
116
}
117
124
// Deprecated since 6.0.0; use elapsed().
125
inline
void
126
stopwatch::compute_elapsed_time
(uint32_t& milliseconds,
127
uint32_t& microseconds)
const
noexcept
128
{
129
const
auto
count =
elapsed
().count ();
130
milliseconds =
static_cast<
uint32_t
>
(count / 1000);
131
microseconds =
static_cast<
uint32_t
>
(count % 1000);
132
}
133
138
// Deprecated since 6.0.0; use start().
139
inline
void
140
stopwatch::timestamp_begin
(
const
timespec& ts)
noexcept
141
{
142
if
(!
is_recorded
(
start_time_
))
143
{
144
start_time_
= ts;
145
}
146
}
147
152
// Deprecated since 6.0.0; use stop().
153
inline
void
154
stopwatch::timestamp_end
(
const
timespec& ts)
noexcept
155
{
156
if
(!
is_recorded
(
stop_time_
))
157
{
158
stop_time_
= ts;
159
}
160
}
161
#endif
// defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
162
163
// --------------------------------------------------------------------------
164
}
// namespace micro_os_plus::micro_test_plus::detail
165
166
#if defined(__GNUC__)
167
#pragma GCC diagnostic pop
168
#endif
// defined(__GNUC__)
169
170
// ----------------------------------------------------------------------------
171
172
#endif
// defined(__cplusplus)
173
174
// ----------------------------------------------------------------------------
175
176
#endif
// MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_STOPWATCH_INLINES_H_
177
178
// ----------------------------------------------------------------------------
micro_os_plus::micro_test_plus::detail::stopwatch::is_recorded
static bool is_recorded(const timespec &ts) noexcept
Checks whether a clock reading was recorded.
Definition
stopwatch-inlines.h:75
micro_os_plus::micro_test_plus::detail::stopwatch::has_begin
bool has_begin(void) const noexcept
Deprecated check of the start reading.
Definition
stopwatch-inlines.h:90
micro_os_plus::micro_test_plus::detail::stopwatch::elapsed
std::chrono::microseconds elapsed(void) const noexcept
Returns the time elapsed between start() and stop().
Definition
stopwatch.cpp:116
micro_os_plus::micro_test_plus::detail::stopwatch::has_elapsed
bool has_elapsed(void) const noexcept
Checks whether the elapsed time is available.
Definition
stopwatch-inlines.h:64
micro_os_plus::micro_test_plus::detail::stopwatch::timestamp_end
void timestamp_end(void) noexcept
Deprecated recording of the stop time, from the system clock.
Definition
stopwatch.cpp:155
micro_os_plus::micro_test_plus::detail::stopwatch::start_time_
timespec start_time_
The clock reading at the start of the measured interval.
Definition
stopwatch.h:430
micro_os_plus::micro_test_plus::detail::stopwatch::timestamp_begin
void timestamp_begin(void) noexcept
Deprecated recording of the start time, from the system clock.
Definition
stopwatch.cpp:139
micro_os_plus::micro_test_plus::detail::stopwatch::has_timestamps
bool has_timestamps(void) const noexcept
Deprecated name of has_elapsed().
Definition
stopwatch-inlines.h:113
micro_os_plus::micro_test_plus::detail::stopwatch::has_end
bool has_end(void) const noexcept
Deprecated check of the stop reading.
Definition
stopwatch-inlines.h:102
micro_os_plus::micro_test_plus::detail::stopwatch::stop_time_
timespec stop_time_
The clock reading at the end of the measured interval.
Definition
stopwatch.h:439
micro_os_plus::micro_test_plus::detail::stopwatch::compute_elapsed_time
void compute_elapsed_time(uint32_t &milliseconds, uint32_t µseconds) const noexcept
Deprecated split of the elapsed time.
Definition
stopwatch-inlines.h:126
micro_os_plus::micro_test_plus::detail
Internal implementation details for the µTest++ framework.
Definition
check-result.h:82
include
micro-os-plus
micro-test-plus
inlines
stopwatch-inlines.h
Generated by
1.18.0