title: C++ clock measures time incorrectly
body: <p>I have a program which reads 2 input files. First file contains some random words which are put into an BST and AVL tree. Then the program looks for the words listed in the second read file and says if they exist in the trees, then writes an output file with the information gathered. While doing this the program prints out the time spent for finding a certain item. However the program does not seem to be measuring the time spent.</p>
  
  <pre><code>BST* b = new BST();
  AVLTree* t = new AVLTree();
  
  string s;
  
  ifstream in;
  in.open(argv[1]);
  
  while(!in.eof())
  {
      in &gt;&gt; s;
      b-&gt;insert(s);
      t-&gt;insert(s);
  }
  
  ifstream q;    
  q.open(argv[2]);
  
  ofstream out;
  out.open(argv[3]);
  
  int bstItem = 0;
  int avlItem = 0;
  float diff1 = 0;
  float diff2 = 0;
  
  clock_t t1, t1e, t2, t2e;
  
  while(!q.eof())
  {
      q &gt;&gt; s;
  
      t1 = clock();
      bstItem = b-&gt;findItem(s);
      t1e = clock();
  
      diff1 = (float)(t1e - t1)/CLOCKS_PER_SEC;        
  
      t2 = clock();
      avlItem = t-&gt;findItem(s);
      t2e = clock();
  
      diff2 = (float)(t2e - t2)/CLOCKS_PER_SEC;
  
      if(avlItem == 0 &amp;&amp; bstItem == 0)
          cout &lt;&lt; "Query " &lt;&lt; s &lt;&lt; " not found in " &lt;&lt; diff1 &lt;&lt; " microseconds in BST, " &lt;&lt; diff2 &lt;&lt; " microseconds in AVL" &lt;&lt; endl;
  
      else
          cout &lt;&lt; "Query " &lt;&lt; s &lt;&lt; " found in " &lt;&lt; diff1 &lt;&lt; " microseconds in BST, " &lt;&lt; diff2 &lt;&lt; " microseconds in AVL" &lt;&lt; endl;
  
      out &lt;&lt; bstItem &lt;&lt; " " &lt;&lt; avlItem &lt;&lt; " " &lt;&lt; s  &lt;&lt; "\n"; 
  }
  </code></pre>
  
  <p>The clock() value I get just before entering while and just after finishing it is exactly the same. So it appears as if the program does not even run the while loop at all, so it print 0. I know that this is not the case since it takes around 10 seconds for the program the finish as it should. Also the output file contains correct results, so the possibility of having bad findItem() functions is also not true.</p>
  
  <p>I did a little bit research in Stack Overflow, and saw that many people experience the same problem as me. However none of the answers I read solved it.</p>