title: Timing Functions: Double Returning 0 MS
body: <p>I am writing an in-depth test program for a data structure I had to write for a class. I am trying to time how long it takes functions to execute and store them in an array for later printing. To double check that it was working I decided to print it immediately, and I found out it is not working.</p>
  
  <p>Here is the code where I get the times and store them in an array that is in a struct.</p>
  
  <pre><code>void test1(ArrayLinkedBag&lt;ItemType&gt; &amp;bag,TestAnalytics &amp;analytics){
      clock_t totalStart;
    clock_t incrementalStart;
    clock_t stop; //Both timers stop at the same time;
    // Start TEST 1
    totalStart = clock();
    bag.debugPrint();
  
    cout &lt;&lt; "Bag Should Be Empty, Checking..." &lt;&lt; endl;
    incrementalStart = clock();
    checkEmpty&lt;ItemType&gt;(bag);
    stop = clock();
    analytics.test1Times[0] = analytics.addTimes(incrementalStart,stop);
    analytics.test1Times[1] = analytics.addTimes(totalStart,stop);
    cout &lt;&lt; analytics.test1Times[0] &lt;&lt; setprecision(5) &lt;&lt; "ms" &lt;&lt; endl;
    std::cout &lt;&lt; "Time: "&lt;&lt; setprecision(5)  &lt;&lt; (stop - totalStart) / (double)(CLOCKS_PER_SEC / 1000) &lt;&lt; " ms" &lt;&lt; std::endl;
      cout &lt;&lt; "===========================================" &lt;&lt; endl; //So I can find the line easier
  
  }
  </code></pre>
  
  <p>Here is the code where I am doing the calculation that I am putting in the array, this function is located in a TestAnalytics struct </p>
  
  <pre><code>double addTimes(double start, double stop){
      return (stop - start)/ (double)(CLOCKS_PER_SEC/1000);
    }
  </code></pre>
  
  <p>Here is a snippet of the output I am getting:</p>
  
  <pre><code>Current Head: -1
  Current Size: 0
  Cell: 1, Index: 0, Item: 6317568, Next Index: -2
  Cell: 2, Index: 1, Item: 4098, Next Index: -2
  Cell: 3, Index: 2, Item: 6317544, Next Index: -2
  Cell: 4, Index: 3, Item: -683175280, Next Index: -2
  Cell: 5, Index: 4, Item: 4201274, Next Index: -2
  Cell: 6, Index: 5, Item: 6317536, Next Index: -2
  Bag Should Be Empty, Checking...
  The Bag Is Empty
  0ms
  Time: 0 ms
  ===========================================
  </code></pre>
  
  <p>I am trying to calculate the time as per a different post on this site.
  I am using clang compiler on an UNIX system. Is it possible that the number is still too small to show above 0?</p>