title: Get average of time spent using std::chrono
body: <p>I have a function running more than a million times. I want to print out the duration of how long the function takes to run by printing the sum of durations of 10,000 calls to the function.</p>
  
  <p>At the start of each function I have something like this:</p>
  
  <pre><code>int counter = 0;
  auto duration_total = 0; //not sure about the type
  std::chrono::high_resolution_clock::time_point t1, t2, duration;
  
  t1 = std::chrono::high_resolution_clock::now(); 
  Function f(){
    counter++;
  }
  
  t2 = std::chrono::high_resolution_clock::now();
  duration= std::chrono::duration_cast&lt;std::chrono::nanoseconds&gt;( t2 - t1 ).count();
  duration_total += duration;
  
  if(counter %10000 == 0){
        long int average_duration = duration_total/10000;
        duration_total = 0;
        cout &lt;&lt; average_duration &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>I can't find a way to add durations and then get their average.</p>