24 #ifndef CLOE_CORE_DURATION_HPP_ 25 #define CLOE_CORE_DURATION_HPP_ 31 #include <nlohmann/json.hpp> 47 using Microseconds = std::chrono::duration<double, std::micro>;
48 using Milliseconds = std::chrono::duration<double, std::milli>;
49 using Seconds = std::chrono::duration<double>;
51 std::string to_string(
const Duration& ns);
55 nlohmann::json to_convenient_json(
const Duration& ns);
69 inline std::string to_string_hr(
double d) {
70 auto n = std::to_string(d);
71 n.erase(n.find_last_not_of(
'0') + 1, std::string::npos);
72 if (n[n.size() - 1] ==
'.') {
79 struct adl_serializer<
cloe::Microseconds> {
80 static void to_json(json& j,
const cloe::Microseconds& us) {
81 j = to_string_hr(us.count()) +
"us";
86 struct adl_serializer<
cloe::Milliseconds> {
87 static void to_json(json& j,
const cloe::Milliseconds& ms) {
88 j = to_string_hr(ms.count()) +
"ms";
93 struct adl_serializer<
cloe::Seconds> {
94 static void to_json(json& j,
const cloe::Seconds& s) { j = to_string_hr(s.count()) +
"s"; }
98 struct adl_serializer<
cloe::Duration> {
100 auto count = ns.count();
102 j = std::chrono::duration_cast<cloe::Seconds>(ns);
103 }
else if (count > 1e6) {
104 j = std::chrono::duration_cast<cloe::Milliseconds>(ns);
105 }
else if (count > 1e3) {
106 j = std::chrono::duration_cast<cloe::Microseconds>(ns);
108 j = to_string_hr(count) +
"ns";
115 #endif // CLOE_CORE_DURATION_HPP_ Definition: coordinator.hpp:36
std::chrono::nanoseconds Duration
Definition: duration.hpp:45
Definition: confable.hpp:132