Function measuring time of another function I wanted to have a function called timeit which can measure the time of execution of n iterations of any other function. I still learning C++ but I come up with that : Any thought ?
#include&lt;chrono&gt;

using namespace std;

template&lt;typename output, typename ...ArgsT, typename ...Input&gt;
double timeit(output (*function)(Input...), int n, ArgsT ...args)
{
   auto start = chrono::high_resolution_clock::now();
   for(int k = 0; k &lt; n; ++k)
   {
      function(args...);
   }
   auto end = chrono::high_resolution_clock::now();
   chrono::duration&lt;double&gt; elapsed = (end-start);
   return elapsed.count();
}
The big thing you're missing here is perfect forwarding. When you receive the argument pack, it may contain one or more rvalue references. But when you pass args... to the function you're timing, you've given a name to the pack, so even though what you received were rvalue references, what you end up passing to the timed function won't be an rvalue reference any more.
To fix this, you'd use std::forward:
function(std::forward&lt;ArgsT&gt;(args)...);

The other obvious addition I'd consider would be gathering and returning the return values from the calls you make. One possibility would be to return something like a pair&lt;double, std::vector&lt;output&gt;&gt;, to hold the time and the return values.