* @brief A utility class to measure execution time for benchmarking purposes. */
| 3426 | * @brief A utility class to measure execution time for benchmarking purposes. |
| 3427 | */ |
| 3428 | class [[nodiscard]] timer |
| 3429 | { |
| 3430 | public: |
| 3431 | /** |
| 3432 | * @brief Get the number of milliseconds that have elapsed since the object was constructed or since `start()` was last called, but keep the timer ticking. |
| 3433 | * |
| 3434 | * @return The number of milliseconds. |
| 3435 | */ |
| 3436 | [[nodiscard]] std::chrono::milliseconds::rep current_ms() const |
| 3437 | { |
| 3438 | return (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time)).count(); |
| 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * @brief Start (or restart) measuring time. Note that the timer starts ticking as soon as the object is created, so this is only necessary if we want to restart the clock later. |
| 3443 | */ |
| 3444 | void start() |
| 3445 | { |
| 3446 | start_time = std::chrono::steady_clock::now(); |
| 3447 | } |
| 3448 | |
| 3449 | /** |
| 3450 | * @brief Stop measuring time and store the elapsed time since the object was constructed or since `start()` was last called. |
| 3451 | */ |
| 3452 | void stop() |
| 3453 | { |
| 3454 | elapsed_time = std::chrono::steady_clock::now() - start_time; |
| 3455 | } |
| 3456 | |
| 3457 | /** |
| 3458 | * @brief Get the number of milliseconds stored when `stop()` was last called. |
| 3459 | * |
| 3460 | * @return The number of milliseconds. |
| 3461 | */ |
| 3462 | [[nodiscard]] std::chrono::milliseconds::rep ms() const |
| 3463 | { |
| 3464 | return (std::chrono::duration_cast<std::chrono::milliseconds>(elapsed_time)).count(); |
| 3465 | } |
| 3466 | |
| 3467 | private: |
| 3468 | /** |
| 3469 | * @brief The time point when measuring started. |
| 3470 | */ |
| 3471 | std::chrono::time_point<std::chrono::steady_clock> start_time = std::chrono::steady_clock::now(); |
| 3472 | |
| 3473 | /** |
| 3474 | * @brief The duration that has elapsed between `start()` and `stop()`. |
| 3475 | */ |
| 3476 | std::chrono::duration<double> elapsed_time = std::chrono::duration<double>::zero(); |
| 3477 | }; // class timer |
| 3478 | |
| 3479 | /** |
| 3480 | * @brief Map a color to a monochrome Unicode block based on its brightness, using luma coefficients. |
nothing calls this directly
no outgoing calls
no test coverage detected