AutoPas  3.0.0
Loading...
Searching...
No Matches
Timer.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <chrono>
11#include <iomanip>
12#include <sstream>
13#include <string>
14
15namespace autopas::utils {
16
20class Timer {
21 public:
22 Timer();
23
24 virtual ~Timer();
25
29 void start();
30
36 long stop();
37
41 void reset();
42
47 void addTime(long nanoseconds);
48
53 [[nodiscard]] long getTotalTime() const { return _totalTime; }
54
60 static std::string getDateStamp(const std::string &format = "%Y-%m-%d_%H-%M-%S") {
61 auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
62 std::ostringstream nowStrStr;
63 tm unused;
64 std::stringstream ss;
65 ss << std::put_time(localtime_r(&now, &unused), format.c_str());
66 return ss.str();
67 }
68
69 private:
73 std::chrono::high_resolution_clock::time_point _startTime;
74
78 long _totalTime = 0;
79
83 bool _currentlyRunning = false;
84};
85} // namespace autopas::utils
Timer class to stop times.
Definition: Timer.h:20
void start()
start the timer.
Definition: Timer.cpp:17
void reset()
Resets the timer to 0.
Definition: Timer.cpp:40
long getTotalTime() const
Get total accumulated time.
Definition: Timer.h:53
static std::string getDateStamp(const std::string &format="%Y-%m-%d_%H-%M-%S")
Create a date stamp for the current moment with the given format.
Definition: Timer.h:60
void addTime(long nanoseconds)
Adds the given amount of nanoseconds to the total time.
Definition: Timer.cpp:42
long stop()
Stops the timer and returns the time elapsed in nanoseconds since the last call to start.
Definition: Timer.cpp:25
In this namespace some helper classes and functions can be found used inside of AutoPas.
Definition: namespaces.h:44