Chebyshev
Unit testing for scientific software
chebyshev::benchmark Namespace Reference

Benchmark module. More...

Namespaces

 generator
 Input generators for benchmarks.
 

Classes

class  benchmark_result
 Structure holding the results of a benchmark. More...
 
class  benchmark_options
 A structure holding the options of a benchmark. More...
 
class  timer
 Timer class to measure elapsed time in milliseconds. More...
 
class  benchmark_settings
 of the benchmark module More...
 
class  benchmark_results
 benchmarks. More...
 

Typedefs

template<typename InputType >
using InputGenerator = std::function< InputType(unsigned int)>
 A function which takes in an index and returns a generated input element.
 

Functions

void setup (std::string moduleName, int argc=0, const char **argv=nullptr)
 Setup the benchmark environment. More...
 
void terminate (bool exit=true)
 Terminate the benchmarking environment. More...
 
template<typename InputType , typename Function >
long double runtime (Function func, const std::vector< InputType > &input)
 Measure the total runtime of a function over the given input for a single run. More...
 
template<typename InputType = double, typename Function >
void benchmark (const std::string &name, Function func, const std::vector< InputType > &input, unsigned int runs=settings.defaultRuns, bool quiet=false)
 Run a benchmark on a generic function, with the given input vector. More...
 
template<typename InputType = double, typename Function >
void benchmark (const std::string &name, Function func, const benchmark_options< InputType > &opt)
 Run a benchmark on a generic function, with the given options. More...
 
template<typename InputType = double, typename Function >
void benchmark (const std::string &name, Function func, unsigned int runs=settings.defaultRuns, unsigned int iterations=settings.defaultIterations, InputGenerator< InputType > inputGenerator=generator::uniform1D(0, 1), bool quiet=false)
 Run a benchmark on a generic function, with the given argument options. More...
 

Variables

struct chebyshev::benchmark::benchmark_settings settings
 
struct chebyshev::benchmark::benchmark_results results
 

Detailed Description

Benchmark module.

This module provides routines for measuring the average runtime of functions of any kind over a randomized or fixed vector of inputs. The benchmark::benchmark implements this functionality and registers the results for analysis and output.

Function Documentation

◆ benchmark() [1/3]

template<typename InputType = double, typename Function >
void chebyshev::benchmark::benchmark ( const std::string &  name,
Function  func,
const benchmark_options< InputType > &  opt 
)
inline

Run a benchmark on a generic function, with the given options.

The result is registered inside results.benchmarkResults.

Parameters
nameThe name of the test case
funcThe function to benchmark
optThe benchmark options

◆ benchmark() [2/3]

template<typename InputType = double, typename Function >
void chebyshev::benchmark::benchmark ( const std::string &  name,
Function  func,
const std::vector< InputType > &  input,
unsigned int  runs = settings.defaultRuns,
bool  quiet = false 
)
inline

Run a benchmark on a generic function, with the given input vector.

The result is registered inside results.benchmarkResults.

Parameters
nameThe name of the test case
funcThe function to benchmark
inputThe vector of input values
runsThe number of runs with the same input

◆ benchmark() [3/3]

template<typename InputType = double, typename Function >
void chebyshev::benchmark::benchmark ( const std::string &  name,
Function  func,
unsigned int  runs = settings.defaultRuns,
unsigned int  iterations = settings.defaultIterations,
InputGenerator< InputType >  inputGenerator = generator::uniform1D(0, 1),
bool  quiet = false 
)
inline

Run a benchmark on a generic function, with the given argument options.

The result is registered inside results.benchmarkResults.

Parameters
nameThe name of the test case
funcThe function to benchmark
runThe number of runs with the same input
iterationsThe number of iterations of the function
inputGeneratorThe input generator to use

◆ runtime()

template<typename InputType , typename Function >
long double chebyshev::benchmark::runtime ( Function  func,
const std::vector< InputType > &  input 
)
inline

Measure the total runtime of a function over the given input for a single run.

It is generally not needed to call this function directly, as benchmarks can be run and registered using benchmark::benchmark.

Parameters
funcThe function to measure the runtime of
inputThe vector of inputs
Returns
The total runtime of the function over the input vector.

◆ setup()

void chebyshev::benchmark::setup ( std::string  moduleName,
int  argc = 0,
const char **  argv = nullptr 
)
inline

Setup the benchmark environment.

Parameters
moduleNameName of the module under test.
argcThe number of command line arguments
argvA list of C-style strings containing the command line arguments.

◆ terminate()

void chebyshev::benchmark::terminate ( bool  exit = true)
inline

Terminate the benchmarking environment.

If benchmarks have been run, their results will be printed.

Parameters
exitWhether to exit after terminating the module.