#pragma once #include #include namespace tools { template class stopwatch { const typename Clock::time_point start_point; public: stopwatch() : start_point(Clock::now()) {} template Rep elapsed_time() const { std::atomic_thread_fence(std::memory_order_relaxed); auto counted_time = std::chrono::duration_cast(Clock::now() - start_point).count(); std::atomic_thread_fence(std::memory_order_relaxed); return static_cast(counted_time); } }; using precise_stopwatch = stopwatch<>; using system_stopwatch = stopwatch; using monotonic_stopwatch = stopwatch; }