Measuring execution time in C++ I had time measuring pretty much figured out when I ended up using this structure.

#include &lt;iostream&gt;
#include &lt;chrono&gt;

template&lt;typename TimeT = std::chrono::milliseconds&gt;
struct measure
{
    template&lt;typename F&gt;
    static typename TimeT::rep execution(F const &amp;func)
    {
        auto start = std::chrono::system_clock::now();
        func();
        auto duration = std::chrono::duration_cast&lt; TimeT&gt;(
            std::chrono::system_clock::now() - start);
        return duration.count();
    }
};


a use case would be

struct functor
{
    int state;
    functor(int state) : state(state) {}
    void operator()() const
    {
        std::cout &lt;&lt; "In functor run for ";
    }
};

void func()
{
    std::cout &lt;&lt; "In function, run for " &lt;&lt; std::endl;
}

void func(int arg) {}

int main()
{
    int dummy(1);

    std::cout &lt;&lt; measure&lt;&gt;::execution( [&amp;]() {  
        func(dummy);
    }) &lt;&lt; std::endl;

    std::cout &lt;&lt; measure&lt;&gt;::execution(functor(dummy)) &lt;&lt; std::endl;
std::cout &lt;&lt; measure&lt;&gt;::execution(func);

    return 0;
}


But since I started using my struct in various posts on Stack Exchange sites, I've had remarks and comments about the code (like on func being a const ref or not etc). 

I'd like a review on the above and your suggestions on how I can approve this code (or leave it alone at last).
Extend your timer function so it can take all the parameters needed by func()
Don bother to pass func by const reference.

What I would have done
template&lt;typename TimeT = std::chrono::milliseconds&gt;
struct measure
{
    template&lt;typename F, typename ...Args&gt;
    static typename TimeT::rep execution(F func, Args&amp;&amp;... args)
    {
        auto start = std::chrono::system_clock::now();

        // Now call the function with all the parameters you need.
        func(std::forward&lt;Args&gt;(args)...);

        auto duration = std::chrono::duration_cast&lt; TimeT&gt;(std::chrono::system_clock::now() - start);

        return duration.count();
    }
};