title: C++11 clocks: g++ steady_clock::is_steady == false?
body: <p>So accurate timing is important to me, and I was investigating the 3 types of clocks specified in C++ 11, namely <code>system_clock</code>, <code>steady_clock</code>, and <code>high_resolution_clock</code>. 
  My initial concern was testing if there is any difference in call overhead to the different types of clocks, and to check the resolution of each type of clock.
  Here is my sample program:</p>
  
  <pre><code>#include &lt;chrono&gt;
  #include &lt;cstdio&gt;
  using namespace std;
  using namespace std::chrono;
  
  int main(int argc, char **argv)
  {
    size_t N = 1e6;
    if(2 == argc) {
      sscanf(argv[1], "%zu", &amp;N);
    }
  
  #if defined(hrc)
    typedef high_resolution_clock clock;
  #warning "High resolution clock"
  #elif defined(sc)
    typedef steady_clock clock;
  #warning "Steady clock"
  #elif defined(sys)
    typedef system_clock clock;
  #warning "System clock"
  #endif
  
    const double resolution = double(clock::period::num) / double(clock::period::den);
  
    printf("clock::period: %lf us.\n", resolution*1e6);
    printf("clock::is_steady: %s\n", clock::is_steady ? "yes" : "no");
    printf("Calling clock::now() %zu times...\n", N);
  
    // first, warm up
    for(size_t i=0; i&lt;100; ++i) {
      time_point&lt;clock&gt; t = clock::now();
    }
  
    // loop N times
    time_point&lt;clock&gt; start = clock::now();
    for(size_t i=0; i&lt;N; ++i) {
      time_point&lt;clock&gt; t = clock::now();
    }
    time_point&lt;clock&gt; end = clock::now();
  
    // display duration
    duration&lt;double&gt; time_span = duration_cast&lt;duration&lt;double&gt;&gt;(end-start);
    const double sec = time_span.count();
    const double ns_it = sec*1e9/N;
    printf("That took %lf seconds. That's %lf ns/iteration.\n", sec, ns_it);
  
    return 0;
  }
  </code></pre>
  
  <p>I compile it with</p>
  
  <pre><code>$ g++-4.7 -std=c++11 -Dhrc chrono.cpp -o hrc_chrono
  chrono.cpp:15:2: warning: #warning "High resolution clock" [-Wcpp]
  $ g++-4.7 -std=c++11 -Dsys chrono.cpp -o sys_chrono
  chrono.cpp:15:2: warning: #warning "System clock" [-Wcpp]
  $ g++-4.7 -std=c++11 -Dsc  chrono.cpp -o sc_chrono
  chrono.cpp:15:2: warning: #warning "Steady clock" [-Wcpp]
  </code></pre>
  
  <p>I compiled with G++ 4.7.2, and ran it on</p>
  
  <ul>
  <li>SUSE Linux, kernel v3.1.10, CPU i7</li>
  <li>Angstrom Linux embedded system, kernel v3.1.10, MCU Tegra 2 (ARM Cortex A9).</li>
  </ul>
  
  <p>The first surprising thing was that the 3 types of clock are apparently synonyms. They all have the same period (1 micro sec), and the time/call is practically the same. <strong>What's the point of specifying 3 types of clocks if they are all the same?</strong> Is this just because the G++ implementation of <code>chrono</code> isn't mature yet? Or maybe the 3.1.10 kernel only has one user-accessible clock?</p>
  
  <p>The second surprise, and this is huge, is that <strong>steady_clock::is_steady == false</strong>. I'm fairly certain that by definition, that property should be true. What gives?? How can I work around it (ie, achieve a steady clock)?</p>
  
  <p>If you can run the simple program on other platforms/compilers, I would be very interested to know the results. If anybody is wondering, it's about 25 ns/iteration on my Core i7, and 1000 ns/iteration on the Tegra 2.</p>