performance_timer.h (803B)
1 // This file is part of AsmJit project <https://asmjit.com> 2 // 3 // See asmjit.h or LICENSE.md for license and copyright information 4 // SPDX-License-Identifier: Zlib 5 6 #ifndef TESTING_PERFORMANCE_TIMER_H_INCLUDED 7 #define TESTING_PERFORMANCE_TIMER_H_INCLUDED 8 9 #include <chrono> 10 11 class PerformanceTimer { 12 public: 13 typedef std::chrono::high_resolution_clock::time_point TimePoint; 14 15 TimePoint _start_time {}; 16 TimePoint _end_time {}; 17 18 inline void start() { 19 _start_time = std::chrono::high_resolution_clock::now(); 20 } 21 22 inline void stop() { 23 _end_time = std::chrono::high_resolution_clock::now(); 24 } 25 26 inline double duration() const { 27 std::chrono::duration<double> elapsed = _end_time - _start_time; 28 return elapsed.count() * 1000; 29 } 30 }; 31 32 #endif // TESTING_PERFORMANCE_TIMER_H_INCLUDED