Home | History | Annotate | Download | only in support
      1 #ifndef TIMER_HPP
      2 #define TIMER_HPP
      3 
      4 // Define LIBCXXABI_NO_TIMER to disable testing with a timer.
      5 #ifndef LIBCXXABI_NO_TIMER
      6 
      7 #include <chrono>
      8 #include <iostream>
      9 
     10 class timer
     11 {
     12     typedef std::chrono::high_resolution_clock Clock;
     13     typedef Clock::time_point TimePoint;
     14     typedef std::chrono::microseconds MicroSeconds;
     15 public:
     16     timer() : m_start(Clock::now()) {}
     17 
     18     timer(timer const &) = delete;
     19     timer & operator=(timer const &) = delete;
     20 
     21     ~timer()
     22     {
     23         using std::chrono::duration_cast;
     24         TimePoint end = Clock::now();
     25         MicroSeconds us = duration_cast<MicroSeconds>(end - m_start);
     26         std::cout << us.count() << " microseconds\n";
     27     }
     28 
     29 private:
     30     TimePoint m_start;
     31 };
     32 
     33 #else /* LIBCXXABI_NO_TIMER */
     34 
     35 class timer
     36 {
     37 public:
     38     timer() {}
     39     timer(timer const &) = delete;
     40     timer & operator=(timer const &) = delete;
     41     ~timer() {}
     42 };
     43 
     44 #endif /* LIBCXXABI_NO_TIMER */
     45 
     46 #endif /* TIMER_HPP */