Timer.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2021, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 #include <chrono>
8 
9 namespace MLCommon {
10 class TimerCPU {
11  public:
12  TimerCPU() { this->reset(); }
13 
14  void reset() { this->time = std::chrono::high_resolution_clock::now(); }
15 
16  double getElapsedSeconds() const
17  {
18  return 1.0e-6 * std::chrono::duration_cast<std::chrono::microseconds>(
19  std::chrono::high_resolution_clock::now() - this->time)
20  .count();
21  }
22 
23  double getElapsedMilliseconds() const
24  {
25  return 1.0e-3 * std::chrono::duration_cast<std::chrono::microseconds>(
26  std::chrono::high_resolution_clock::now() - this->time)
27  .count();
28  }
29 
30  private:
31  std::chrono::high_resolution_clock::time_point time;
32 };
33 } // End namespace MLCommon
Definition: Timer.h:10
double getElapsedMilliseconds() const
Definition: Timer.h:23
double getElapsedSeconds() const
Definition: Timer.h:16
TimerCPU()
Definition: Timer.h:12
void reset()
Definition: Timer.h:14
Definition: Timer.h:9