Skip to content

Commit

Permalink
Rename Timer to Stopwatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Sep 13, 2024
1 parent c352658 commit a60996e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tesseract_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ add_library(
src/plugin_info.cpp
src/resource_locator.cpp
src/types.cpp
src/timer.cpp)
src/stopwatch.cpp)
target_link_libraries(
${PROJECT_NAME}
PUBLIC Eigen3::Eigen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file timer.h
* @brief Simple timer class using chrono
* @file stopwatch.h
* @brief Simple stopwatch class using chrono
*
* @author Levi Armstrong
* @date February 2, 2021
Expand All @@ -23,8 +23,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TESSERACT_COMMON_TIMER_H
#define TESSERACT_COMMON_TIMER_H
#ifndef TESSERACT_COMMON_STOPWATCH_H
#define TESSERACT_COMMON_STOPWATCH_H

#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Expand All @@ -33,10 +33,10 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP

namespace tesseract_common
{
/** @brief A simple timer class leveraging chrono high resolution clock */
class Timer
/** @brief A simple stopwatch class leveraging chrono high resolution clock */
class Stopwatch
{
using Clock = std::chrono::high_resolution_clock;
using Clock = std::chrono::steady_clock;

public:
/** @brief Start the timer */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file timer.cpp
* @brief Simple timer class using chrono
* @file stopwatch.cpp
* @brief Simple stopwatch class using chrono
*
* @author Levi Armstrong
* @date February 2, 2021
Expand All @@ -24,30 +24,30 @@
* limitations under the License.
*/

#include <tesseract_common/timer.h>
#include <tesseract_common/stopwatch.h>

namespace tesseract_common
{
void Timer::start()
void Stopwatch::start()
{
start_time_ = Clock::now();
running_ = true;
}

void Timer::stop()
void Stopwatch::stop()
{
end_time_ = Clock::now();
running_ = false;
}

double Timer::elapsedMilliseconds() const
double Stopwatch::elapsedMilliseconds() const
{
if (running_)
return std::chrono::duration<double, std::milli>(Clock::now() - start_time_).count();

return std::chrono::duration<double, std::milli>(end_time_ - start_time_).count();
}

double Timer::elapsedSeconds() const { return (elapsedMilliseconds() / 1000.0); }
double Stopwatch::elapsedSeconds() const { return (elapsedMilliseconds() / 1000.0); }

} // namespace tesseract_common

0 comments on commit a60996e

Please sign in to comment.