|
26 | 26 | #include <gsl/gsl_cdf.h> // GSL header for chisqrd distribution |
27 | 27 |
|
28 | 28 | #include <algorithm> |
| 29 | +#include <chrono> |
29 | 30 | #include <cmath> |
30 | 31 | #include <filesystem> |
31 | 32 | #include <fstream> |
|
36 | 37 | #include <thread> |
37 | 38 | #include <vector> |
38 | 39 |
|
| 40 | +[[nodiscard]] static std::string |
| 41 | +format_duration(const std::chrono::duration<double> elapsed) { |
| 42 | + static constexpr auto s_per_h = 3600; |
| 43 | + static constexpr auto s_per_m = 60; |
| 44 | + const double tot_s = elapsed.count(); |
| 45 | + |
| 46 | + // break down into hours, minutes, seconds |
| 47 | + const std::uint32_t hours = tot_s / 3600; |
| 48 | + const std::uint32_t minutes = (static_cast<int>(tot_s) % s_per_h) / s_per_m; |
| 49 | + const double seconds = tot_s - (hours * s_per_h) - (minutes * s_per_m); |
| 50 | + |
| 51 | + std::ostringstream oss; |
| 52 | + oss << std::setfill('0') << std::setw(2) << hours << ":" << std::setfill('0') |
| 53 | + << std::setw(2) << minutes << ":" << std::fixed << std::setprecision(2) |
| 54 | + << std::setw(5) << seconds; |
| 55 | + return oss.str(); |
| 56 | +} |
| 57 | + |
39 | 58 | struct file_progress { |
40 | 59 | double one_thousand_over_filesize{}; |
41 | 60 | std::size_t prev_offset{}; |
@@ -454,8 +473,14 @@ main_radmeth(int argc, char *argv[]) { |
454 | 473 | if (verbose) |
455 | 474 | std::cerr << "Null model:\n" << null_model.design << '\n'; |
456 | 475 |
|
| 476 | + const auto start_time = std::chrono::steady_clock::now(); |
457 | 477 | radmeth(show_progress, more_na_info, n_threads, table_filename, outfile, |
458 | 478 | alt_model, null_model, test_factor_idx); |
| 479 | + const auto stop_time = std::chrono::steady_clock::now(); |
| 480 | + |
| 481 | + if (verbose) |
| 482 | + std::cerr << "[total time: " << format_duration(stop_time - start_time) |
| 483 | + << "]\n"; |
459 | 484 | } |
460 | 485 | catch (const std::exception &e) { |
461 | 486 | std::cerr << e.what() << '\n'; |
|
0 commit comments