Timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 #include <chrono>
19 
20 namespace MLCommon {
21 class TimerCPU {
22  public:
23  TimerCPU() { this->reset(); }
24 
25  void reset() { this->time = std::chrono::high_resolution_clock::now(); }
26 
27  double getElapsedSeconds() const
28  {
29  return 1.0e-6 * std::chrono::duration_cast<std::chrono::microseconds>(
30  std::chrono::high_resolution_clock::now() - this->time)
31  .count();
32  }
33 
34  double getElapsedMilliseconds() const
35  {
36  return 1.0e-3 * std::chrono::duration_cast<std::chrono::microseconds>(
37  std::chrono::high_resolution_clock::now() - this->time)
38  .count();
39  }
40 
41  private:
42  std::chrono::high_resolution_clock::time_point time;
43 };
44 } // End namespace MLCommon
Definition: Timer.h:21
double getElapsedMilliseconds() const
Definition: Timer.h:34
double getElapsedSeconds() const
Definition: Timer.h:27
TimerCPU()
Definition: Timer.h:23
void reset()
Definition: Timer.h:25
Definition: kernelparams.h:21