| Line | Branch | Exec | Source | 
|---|---|---|---|
| 1 | #ifndef LYTHON_UTILITIES_CHRONO_HEADER | ||
| 2 | #define LYTHON_UTILITIES_CHRONO_HEADER | ||
| 3 | |||
| 4 | #include <chrono> | ||
| 5 | #include <ratio> | ||
| 6 | |||
| 7 | namespace lython { | ||
| 8 | template <typename T = double, typename Unit = std::chrono::milliseconds> | ||
| 9 | class StopWatch { | ||
| 10 | public: | ||
| 11 | using TimePoint = std::chrono::high_resolution_clock::time_point; | ||
| 12 | using Clock = std::chrono::high_resolution_clock; | ||
| 13 | using Duration = std::chrono::duration<T>; | ||
| 14 | |||
| 15 | TimePoint const start = Clock::now(); | ||
| 16 | |||
| 17 | double stop() const { | ||
| 18 | 171417 | TimePoint end = Clock::now(); | |
| 19 | 1/2✓ Branch 1 taken 171417 times. ✗ Branch 2 not taken. | 342834 | return StopWatch::diff(start, end); | 
| 20 | } | ||
| 21 | |||
| 22 | static double diff(TimePoint start, TimePoint end) { | ||
| 23 | 2/4✓ Branch 1 taken 171419 times. ✗ Branch 2 not taken. ✓ Branch 4 taken 171419 times. ✗ Branch 5 not taken. | 171419 | Duration time_delta = end - start; | 
| 24 | 1/2✓ Branch 1 taken 171419 times. ✗ Branch 2 not taken. | 171419 | auto delta = std::chrono::duration_cast<Unit>(time_delta); | 
| 25 | 171419 | return double(delta.count()); | |
| 26 | } | ||
| 27 | |||
| 28 | StopWatch operator=(StopWatch p) { return StopWatch(p); } | ||
| 29 | |||
| 30 | StopWatch(const StopWatch& p): start(p.start) {} | ||
| 31 | |||
| 32 | StopWatch() = default; | ||
| 33 | }; | ||
| 34 | |||
| 35 | } // namespace lython | ||
| 36 | |||
| 37 | #endif | ||
| 38 |