29 #include <nlohmann/json.hpp>
43 using Duration = std::chrono::nanoseconds;
45 using Microseconds = std::chrono::duration<double, std::micro>;
46 using Milliseconds = std::chrono::duration<double, std::milli>;
47 using Seconds = std::chrono::duration<double>;
49 std::string to_string(
const Duration& ns);
53 nlohmann::json to_convenient_json(
const Duration& ns);
67 inline std::string to_string_hr(
double d) {
68 auto n = std::to_string(d);
69 n.erase(n.find_last_not_of(
'0') + 1, std::string::npos);
70 if (n[n.size() - 1] ==
'.') {
77 struct adl_serializer<cloe::Microseconds> {
78 static void to_json(json& j,
const cloe::Microseconds& us) {
79 j = to_string_hr(us.count()) +
"us";
84 struct adl_serializer<cloe::Milliseconds> {
85 static void to_json(json& j,
const cloe::Milliseconds& ms) {
86 j = to_string_hr(ms.count()) +
"ms";
91 struct adl_serializer<cloe::Seconds> {
92 static void to_json(json& j,
const cloe::Seconds& s) { j = to_string_hr(s.count()) +
"s"; }
96 struct adl_serializer<cloe::Duration> {
98 auto count = ns.count();
100 j = std::chrono::duration_cast<cloe::Seconds>(ns);
101 }
else if (count > 1e6) {
102 j = std::chrono::duration_cast<cloe::Milliseconds>(ns);
103 }
else if (count > 1e3) {
104 j = std::chrono::duration_cast<cloe::Microseconds>(ns);
106 j = to_string_hr(count) +
"ns";
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36