19 #ifndef SINGA_UTILS_TIMER_H 20 #define SINGA_UTILS_TIMER_H 29 typedef std::chrono::duration<int> Seconds;
30 typedef std::chrono::duration<int, std::milli> Milliseconds;
31 typedef std::chrono::duration<int, std::ratio<60 * 60>> Hours;
32 typedef std::chrono::duration<int, std::micro> Microseconds;
37 void Tick() { last_ = std::chrono::high_resolution_clock::now(); }
41 template <
typename T = Milliseconds>
43 static_assert(std::is_same<T, Seconds>::value ||
44 std::is_same<T, Milliseconds>::value ||
45 std::is_same<T, Hours>::value ||
46 std::is_same<T, Microseconds>::value,
47 "Template arg must be Seconds | Milliseconds | Hours | Microseconds");
48 auto now = std::chrono::high_resolution_clock::now();
49 return std::chrono::duration_cast<T>(now - last_).count();
55 std::chrono::high_resolution_clock::time_point last_;
int Elapsed() const
Return the duration since last call to Tick() or since the creation of Timer.
Definition: timer.h:42
void Tick()
Reset the internal time point to the current time.
Definition: timer.h:37
Timer()
Init the internal time point to the current time.
Definition: timer.h:35
For benchmarking the time cost of operations.
Definition: timer.h:27
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48