eztimer
Easy timing of C++ functions
Loading...
Searching...
No Matches
eztimer Namespace Reference

Easy timing of C++ functions. More...

Classes

struct  Options
 Options for time(). More...
 
struct  Timings
 Timings for each function. More...
 

Functions

template<typename Result_ >
std::vector< Timingstime (const std::vector< std::function< Result_()> > &funs, const std::function< void(const Result_ &, std::size_t)> &check, const Options &opt)
 

Detailed Description

Easy timing of C++ functions.

Function Documentation

◆ time()

template<typename Result_ >
std::vector< Timings > eztimer::time ( const std::vector< std::function< Result_()> > & funs,
const std::function< void(const Result_ &, std::size_t)> & check,
const Options & opt )

Record the execution time of any number of functions, possibly over multiple iterations. When multiple functions are supplied, they are called in a random order per iteration to avoid any dependencies. Burn-in iterations are performed at the start to ensure any initialization effects do not distort the timings. The per-function or total runtime can also be capped, in which case the actual number of iterations for a function may be less than Options::iterations.

Parameters
funsVector of functions to be timed. Each function should return a value that depends on the computation of interest, to ensure that the latter is not optimized away by the compiler.
checkFunction that accepts a Result_ and an index of funs, and performs some kind of check on the former. Any check is fine as long as it uses the value returned by funs. The runtime of this function will not be included in the timings.
optFurther options.
Returns
Vector of length equal to funs.size(), containing the timings for each function.
Template Parameters
Result_Result of each function call.