I want to make a function to test the running time of the incoming function. I use templates to make it applicable to many functions.
I omitted the code for counting time. like this:
template<typename F>
void get_run_time(F func)
{
//time start
func;
//time end
}
But if a function I pass in is void
, an error will be report and prompt me to add F=void
.
I tried to add it, but it didn't work. I can change void to bool, but it's very strange.
Another problem is that I want to test a function time and run my whole code normally .So I increased the return value. like this:
template<typename F>
F get_run_time(F func)
{
//time start
F tf=func;
//time end
return tf;
}
But the actual test time is obviously wrong. I guess it starts to run the function when it return .How can it get the running results before continuing with the following code?