title: Measuring Runtime - Not Precise Enough
body: <p>I've got an assignment here. The programming side of it should be relatively simple, but I can't seem to get results here. We are to implement merge sort and radix sort and then test them on groups of random numbers. Test it ten times for n = 10, n = 100, n = 1000, and n = 10000, averaging each of the ten tests to get an average runtime. Sounds simple enough, but I can't seem to get any results for n = 10, and the results for n = 100 and n = 1000 aren't very precise. The most I can get out of them is something like, .0001.</p>
  
  <p>The point of the assignment is to compare these runtimes to the theoretical runtimes, but we've never discussed how to handle getting a runtime, so the most any of us can do is Google aimlessly in hopes of finding something that works.</p>
  
  <p>I've tried a few different methods of doing this, and none of them have produced adequate results. The most recent attempt is by using chrono and the high_resolution_clock. Still no good. I even tried putting my computer under a stress test and running the program while at ~100% load and it still didn't work.</p>
  
  <pre><code>for(int cnt = 0; cnt &lt; 10; cnt++)
  {
      populate(numbers, 10);
      high_resolution_clock::time_point t1 = high_resolution_clock::now();
      mergeSort(numbers,0,numbers.size()-1);
      high_resolution_clock::time_point t2 = high_resolution_clock::now();
  
      auto duration = std::chrono::duration_cast&lt;std::chrono::nanoseconds&gt;(t2-t1).count();
      dur += duration;
  }
  
  cout &lt;&lt; endl &lt;&lt; "For N = 10, Mergesort Average Runtime: " &lt;&lt; dur/10;
  dur = 0;
  </code></pre>