title: Comparing the time measured results produced by rdtsc clock and c++11 std::chrono::high_resolution_clock
body: <p>I am trying to compare the times measured by c++11 <code>std::chrono::high_resolution_clock</code> and the <code>rdtsc_clock</code> clock at below. From the <code>high_resolution_clock</code>, I am getting result like 11000, 3000, 1000, 0. From the <code>rdtsc_clock</code>, I am getting 134, 15, 91 etc. Why their result look so differently? From my gut feeling, I believe the <code>rdtsc_clock</code> is presenting the ~accurate results, am I right?</p>
  
  <pre><code>    template&lt;std::intmax_t clock_freq&gt;
      struct rdtsc_clock {
          typedef unsigned long long rep;
          typedef std::ratio&lt;1, clock_freq&gt; period;
          typedef std::chrono::duration&lt;rep, period&gt; duration;
          typedef std::chrono::time_point&lt;rdtsc_clock&gt; time_point;
          static const bool is_steady = true;
  
          static time_point now() noexcept
          {
  
              unsigned lo, hi;
              asm volatile("rdtsc" : "=a" (lo), "=d" (hi));
  
              return time_point(duration(static_cast&lt;rep&gt;(hi) &lt;&lt; 32 | lo));
          }
      };
  </code></pre>
  
  <p>The timing code:</p>
  
  <pre><code>typedef std::chrono::high_resolution_clock Clock;
  //typedef rdtsc_clock&lt;3300000000&gt; Clock;
  typedef std::chrono::nanoseconds nanoseconds;
  typedef std::chrono::duration&lt;double, typename Clock::period&gt; Cycle;
  for(int n=0; n &lt; 10; n++){
     auto t1 = Clock::now();
     //codes
     auto t2 = Clock::now();
     printf(%.0f ns \n", duration_cast&lt;nanoseconds&gt;(Cycle(t2 - t1)).count());
  }
  </code></pre>