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);
72 nlohmann::json to_convenient_json(
const Duration& ns);
86 inline std::string to_string_hr(
double d) {
87 auto n = std::to_string(d);
88 n.erase(n.find_last_not_of(
'0') + 1, std::string::npos);
89 if (n[n.size() - 1] ==
'.') {
96 struct adl_serializer<cloe::Microseconds> {
97 static void to_json(json& j,
const cloe::Microseconds& us) {
98 j = to_string_hr(us.count()) +
"us";
103 struct adl_serializer<cloe::Milliseconds> {
104 static void to_json(json& j,
const cloe::Milliseconds& ms) {
105 j = to_string_hr(ms.count()) +
"ms";
110 struct adl_serializer<cloe::Seconds> {
111 static void to_json(json& j,
const cloe::Seconds& s) { j = to_string_hr(s.count()) +
"s"; }
115 struct adl_serializer<cloe::Duration> {
117 auto count = ns.count();
119 j = std::chrono::duration_cast<cloe::Seconds>(ns);
120 }
else if (count > 1e6) {
121 j = std::chrono::duration_cast<cloe::Milliseconds>(ns);
122 }
else if (count > 1e3) {
123 j = std::chrono::duration_cast<cloe::Microseconds>(ns);
125 j = to_string_hr(count) +
"ns";
Duration parse_duration(const std::string &s)
Definition: chrono.hpp:56
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36