1 //===----------------------------------------------------------------------===//// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===//// 9 10 #ifndef TIMER_HPP 11 #define TIMER_HPP 12 13 // Define LIBCXXABI_NO_TIMER to disable testing with a timer. 14 #ifndef LIBCXXABI_NO_TIMER 15 16 #include <chrono> 17 #include <iostream> 18 19 class timer 20 { 21 typedef std::chrono::high_resolution_clock Clock; 22 typedef Clock::time_point TimePoint; 23 typedef std::chrono::microseconds MicroSeconds; 24 public: timer()25 timer() : m_start(Clock::now()) {} 26 27 timer(timer const &) = delete; 28 timer & operator=(timer const &) = delete; 29 ~timer()30 ~timer() 31 { 32 using std::chrono::duration_cast; 33 TimePoint end = Clock::now(); 34 MicroSeconds us = duration_cast<MicroSeconds>(end - m_start); 35 std::cout << us.count() << " microseconds\n"; 36 } 37 38 private: 39 TimePoint m_start; 40 }; 41 42 #else /* LIBCXXABI_NO_TIMER */ 43 44 class timer 45 { 46 public: timer()47 timer() {} 48 timer(timer const &) = delete; 49 timer & operator=(timer const &) = delete; ~timer()50 ~timer() {} 51 }; 52 53 #endif /* LIBCXXABI_NO_TIMER */ 54 55 #endif /* TIMER_HPP */ 56