title: Running time of functions
body: <p>I am wanting to print the running time of my functions. For some reason my timer always returns 0. Can anyone tell me why? </p>
  
  <pre><code>double RunningTime(clock_t time1, clock_t time2)
  {
      double t=time1 - time2;
      double time = (t*1000)/CLOCKS_PER_SEC;
      return time;
  }
  
  int main()
  {
       clock_t start_time = clock();
  
  
       // some code.....
  
  
      clock_t end_time = clock();
  
      std::cout &lt;&lt; "Time elapsed: " &lt;&lt; double(RunningTime(end_time, start_time)) &lt;&lt; " ms";
  
      return 0;
  }
  </code></pre>
  
  <p>I attempted to use <code>gettimeofday</code> and it still returned 0.</p>
  
  <pre><code>double get_time()
  {
      struct timeval t;
      gettimeofday(&amp;t, NULL);
      double d = t.tv_sec + (double) t.tv_usec/100000;
      return d;
  }
  
  int main()
  {
          double time_start = get_time();
  
          //Some code......
  
          double time_end = get_time();
  
          std::cout &lt;&lt; time_end - time_start;
  
      return 0;
  }
  </code></pre>
  
  <p>Also tried using <code>chrono</code> and it gave me all kinds of build errors:</p>
  
  <ul>
  <li>error: #error This file requires compiler and library support for the
  upcoming ISO C++ standard, C++0x. This support is currently<br>
  experimental, and must be enabled with the -std=c++0x or -std=gnu++0x
  compiler options.</li>
  <li>warning: 'auto' will change meaning in C++0x;    please remove it</li>
  <li>error: ISO C++ forbids declaration of 't1' with no    type error:
  'std::chrono' has not been declared</li>
  <li><p>error: request for member 'count'    in '(t2 - t1)', which is of
  non-class type 'int'</p>
  
  <p>int main()
          {
                  auto t1 = std::chrono::high_resolution_clock::now();</p>
  
  <pre><code>            //Some code......
  
              auto t2 = std::chrono::high_resolution_clock::now();
  
              std::cout &lt;&lt; "Time elapsed: " &lt;&lt; std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(t2-t1).count() &lt;&lt; " milliseconds\n";
  
          return 0;
      }
  </code></pre></li>
  </ul>