15 #ifndef TRAFFIC_SIMULATOR__HELPER__STOP_WATCH_HPP_
16 #define TRAFFIC_SIMULATOR__HELPER__STOP_WATCH_HPP_
21 #include <rclcpp/rclcpp.hpp>
42 end_time = std::nullopt;
43 start_time = std::chrono::system_clock::now();
45 void stop() { end_time = std::chrono::system_clock::now(); }
49 if (start_time && end_time) {
51 std::chrono::duration_cast<T>(end_time.value() - start_time.value()).count();
52 if (
typeid(T) ==
typeid(std::chrono::microseconds)) {
53 std::cout <<
"elapsed time in stop watch " <<
name <<
" : " << elapsed <<
" microseconds"
56 if (
typeid(T) ==
typeid(std::chrono::milliseconds)) {
57 std::cout <<
"elapsed time in stop watch " <<
name <<
" : " << elapsed <<
" milliseconds"
60 if (
typeid(T) ==
typeid(std::chrono::seconds)) {
61 std::cout <<
"elapsed time in stop watch " <<
name <<
" : " << elapsed <<
" seconds"
68 rclcpp::get_logger(
name),
"Stop watch : " <<
name <<
" did not started.");
72 rclcpp::get_logger(
name),
"Stop watch : " <<
name <<
" did not stopped.");
82 std::optional<std::chrono::system_clock::time_point> start_time, end_time;
Definition: stop_watch.hpp:30
const bool verbose
Definition: stop_watch.hpp:79
void start()
Definition: stop_watch.hpp:40
void stop()
Definition: stop_watch.hpp:45
StopWatch(const std::string &name, bool verbose=false, bool autostart=true)
Definition: stop_watch.hpp:32
void print()
Definition: stop_watch.hpp:46
const std::string name
Definition: stop_watch.hpp:78
std::string string
Definition: junit5.hpp:26