Skip to content

Commit 22e06ea

Browse files
src/radmeth/radmeth.cpp: added code to time the run
1 parent 1bf7800 commit 22e06ea

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/radmeth/radmeth.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <gsl/gsl_cdf.h> // GSL header for chisqrd distribution
2727

2828
#include <algorithm>
29+
#include <chrono>
2930
#include <cmath>
3031
#include <filesystem>
3132
#include <fstream>
@@ -36,6 +37,24 @@
3637
#include <thread>
3738
#include <vector>
3839

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+
3958
struct file_progress {
4059
double one_thousand_over_filesize{};
4160
std::size_t prev_offset{};
@@ -454,8 +473,14 @@ main_radmeth(int argc, char *argv[]) {
454473
if (verbose)
455474
std::cerr << "Null model:\n" << null_model.design << '\n';
456475

476+
const auto start_time = std::chrono::steady_clock::now();
457477
radmeth(show_progress, more_na_info, n_threads, table_filename, outfile,
458478
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";
459484
}
460485
catch (const std::exception &e) {
461486
std::cerr << e.what() << '\n';

0 commit comments

Comments
 (0)