title: clock() function always returning 0
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2134363/the-c-clock-function-just-returns-a-zero">The C <code>clock()</code> function just returns a zero</a>  </p>
  </blockquote>
  
  
  
  <p>I ran the following code to test the working of clock() function. I work on ubuntu 12.04.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  
  double diffclock(clock_t clock1,clock_t clock2)
  {
  double diffticks=clock1-clock2;
  double diffms=(diffticks*10)/CLOCKS_PER_SEC;
  return diffms;
  }
  
  int main()
  {
  string name;
  int i;
  clock_t begin=clock();
  cout &lt;&lt; "Hi what is your name? ";
  getline(cin, name);
  clock_t end=clock();
  cout &lt;&lt; "Time elapsed: " &lt;&lt; double(diffclock(end,begin)) &lt;&lt; " ms"&lt;&lt; endl;
  return 0;
  }
  </code></pre>
  
  <p>But no matter how much time i take to write my name, the time elapsed is always shown as 0ms.</p>
  
  <p>Can you tell me what is the problem?</p>