title: Using gettimeofday to measure execution time results in weird behaviour
body: <p>I am using gettimeofday to measure the execution time of a function i wrote in c++ native code for an android app. I created a timer class to help me accomplish this:</p>
  
  <pre><code>timer::timer(){Reset();}
  
  timer::Reset(){
      timeval t;
      gettimeofday(&amp;t, 0);
      start_s = t.tv_sec;
      start_ms = t.tv_usec * 0.001f;
  }
  
  timer::GetTime(){
      timeval t;
      gettimeofday(&amp;t, 0);
      return (t.tv_sec - start_s)*1000 + t.tv_usec * 0.001f - start_ms;
  }
  </code></pre>
  
  <p>Then, in my main code, I create two timer objects and perform a measurement as follows:</p>
  
  <pre><code>main(){
      timer t1, t2;
      stringstream str1;
      t1.Reset();
      for (some count){
          t2.Reset();
          some_function();
          str1 &lt;&lt; t2.GetTime() &lt;&lt; " ";
      }
      str1 &lt;&lt; t1.GetTime();
  
      output str1;
  }
  </code></pre>
  
  <p>But the problem is, when I look at my output results, t1 is almost identical to all the t2 values. An example of the output might be "0.5 0.5 0.4 0.4 0.5 0.55" if the for loop ran five times.</p>
  
  <p>I can't figure out why this might happen.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks.</p>