| 347 | } |
| 348 | |
| 349 | std::string toString(std::chrono::nanoseconds d) { |
| 350 | // bunch of constants to help us round up and convert with appropriate |
| 351 | // suffix. For example say 90ns or 5.6us or 5.5ms or 55s etc |
| 352 | constexpr uint64_t micros = |
| 353 | std::chrono::nanoseconds(std::chrono::microseconds(1)).count(); |
| 354 | constexpr uint64_t millis = |
| 355 | std::chrono::nanoseconds(std::chrono::milliseconds(1)).count(); |
| 356 | constexpr uint64_t secs = |
| 357 | std::chrono::nanoseconds(std::chrono::seconds(1)).count(); |
| 358 | |
| 359 | uint64_t count = d.count(); |
| 360 | if (count < micros) { |
| 361 | return fmt::format("{}ns", count); |
| 362 | } else if (count < millis) { |
| 363 | return fmt::format("{:.2f}us", static_cast<double>(count) / micros); |
| 364 | } else if (count < secs) { |
| 365 | return fmt::format("{:.2f}ms", static_cast<double>(count) / millis); |
| 366 | } else { |
| 367 | return fmt::format("{:.2f}s", static_cast<double>(count) / secs); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | namespace { |
| 372 | // char to int conversion |