Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
execution_timer.hpp
1 // Copyright (c) 2018 Intel Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_UTIL__EXECUTION_TIMER_HPP_
16 #define NAV2_UTIL__EXECUTION_TIMER_HPP_
17 
18 #include <chrono>
19 
20 namespace nav2_util
21 {
22 
25 {
26 public:
27  using Clock = std::chrono::high_resolution_clock;
28  using nanoseconds = std::chrono::nanoseconds;
29 
31  void start() {start_ = Clock::now();}
32 
34  void end() {end_ = Clock::now();}
35 
37  nanoseconds elapsed_time() {return end_ - start_;}
38 
41  {
42  return std::chrono::duration<double>(end_ - start_).count();
43  }
44 
45 protected:
46  Clock::time_point start_;
47  Clock::time_point end_;
48 };
49 
50 } // namespace nav2_util
51 
52 #endif // NAV2_UTIL__EXECUTION_TIMER_HPP_
Measures execution time of code between calls to start and end.
void start()
Call just prior to code you want to measure.
double elapsed_time_in_seconds()
Extract the measured time as a floating point number of seconds.
nanoseconds elapsed_time()
Extract the measured time as an integral std::chrono::duration object.
void end()
Call just after the code you want to measure.