Even better, as user673679 user673679 and JDługosz JDługosz mentioned, there is no need to have a class TimedTest
, you can just write a function that takes another function as an argument and runs that in a loop. The only difference with your code would then be that you interleave running each test once, and accumulate results, and at the end calculate all the averages.
Even better, as user673679 and JDługosz mentioned, there is no need to have a class TimedTest
, you can just write a function that takes another function as an argument and runs that in a loop. The only difference with your code would then be that you interleave running each test once, and accumulate results, and at the end calculate all the averages.
Even better, as user673679 and JDługosz mentioned, there is no need to have a class TimedTest
, you can just write a function that takes another function as an argument and runs that in a loop. The only difference with your code would then be that you interleave running each test once, and accumulate results, and at the end calculate all the averages.
Avoid new
anand delete
Even better, as user673679user673679 and JDługoszJDługosz mentioned, there is no need to have a class TimedTest
, you can just write a function that takes another function as an argument and runs that in a loop. The only difference with your code would then be that you interleave running each test once, and accumulate results, and at the end calculate all the averages.
Avoid new
an delete
Even better, as user673679 and JDługosz mentioned, there is no need to have a class TimedTest
, you can just write a function that takes another function as an argument and runs that in a loop. The only difference with your code would then be that you interleave running each test once, and accumulate results, and at the end calculate all the averages.
Avoid new
and delete
Even better, as user673679 and JDługosz mentioned, there is no need to have a class TimedTest
, you can just write a function that takes another function as an argument and runs that in a loop. The only difference with your code would then be that you interleave running each test once, and accumulate results, and at the end calculate all the averages.
Use auto
and using
to avoid writing long type names
Instead of writing out full type names like in this line of code:
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
I recommend you use using
to create a type alias for the clock type you want to use, and auto
to avoid having to specify types at all where appropriate. The above then becomes:
using clock = std::chrono::steady_clock;
auto start = clock::now();
...
auto stop = clock::now();
Use auto
and using
to avoid writing long type names
Instead of writing out full type names like in this line of code:
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
I recommend you use using
to create a type alias for the clock type you want to use, and auto
to avoid having to specify types at all where appropriate. The above then becomes:
using clock = std::chrono::steady_clock;
auto start = clock::now();
...
auto stop = clock::now();