Skip to content

Fixed timer class #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions src/tools/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ class Timer {

private:
string name;

vector<std::chrono::high_resolution_clock::time_point> starts;
vector<std::chrono::high_resolution_clock::time_point> stops;

std::chrono::high_resolution_clock::time_point time_start;
vector<std::chrono::duration<double>> intervals;

std::chrono::duration<double> total;

public:
Expand All @@ -54,45 +50,26 @@ class Timer {

/// start: start timer i.e. set initial time stamp
///////////////////////////////////////////////////

void start() { starts.push_back(std::chrono::high_resolution_clock::now()); }
void start() { time_start = std::chrono::high_resolution_clock::now(); }

/// stop: stop timer and calculate interval for every process
//////////////////////////////////////////////////////////////

void stop() {
stops.push_back(std::chrono::high_resolution_clock::now());

const std::chrono::duration<double> interval = stops.back() - starts.back();

const std::chrono::high_resolution_clock::time_point time_stop =
std::chrono::high_resolution_clock::now();
const std::chrono::duration<double> interval = time_stop - time_start;
intervals.push_back(interval);

total += interval;
}

/// print_to_file: print time interval to file
///////////////////////////////////////////////

// void print_to_file ()
//{
// string file_name = output_folder + "timer_" + name + ".txt";

// ofstream outFile (file_name, ios_base::app);

// outFile << interval.count() << endl;

// outFile.close();
//}

/// print: print time interval to screen
/////////////////////////////////////////

string get_print_string() {
return ("T | " + name + " : " + to_string(intervals.back().count()) + " seconds");
return ("T | " + name + " : " + std::to_string(intervals.back().count()) + " seconds");
}

string get_print_total_string() {
return ("Tot | " + name + " : " + to_string(total.count()) + " seconds");
return ("Tot | " + name + " : " + std::to_string(total.count()) + " seconds");
}

void print() { cout << get_print_string() << endl; }
Expand Down