Chebyshev
Unit testing for scientific software
Loading...
Searching...
No Matches
chebyshev::benchmark::benchmark_context Class Reference

Benchmark module context, handling benchmark requests concurrently. More...

#include <benchmark.h>

Public Member Functions

void setup (std::string moduleName, int argc=0, const char **argv=nullptr)
 Setup the benchmark environment.
 
void terminate (bool exit=false)
 Terminate the benchmarking environment.
 
 benchmark_context (std::string moduleName, int argc=0, const char **argv=nullptr)
 Default constructor setting up the context.
 
 ~benchmark_context ()
 Terminate the benchmark module.
 
 benchmark_context (const benchmark_context &other)
 Custom copy constructor to avoid copying std::mutex.
 
benchmark_contextoperator= (const benchmark_context &other)
 Custom assignment operator to avoid copying std::mutex.
 
template<typename InputType = double, typename Function >
void benchmark (const std::string &name, Function func, const std::vector< InputType > &input, unsigned int runs=0, bool quiet=false)
 Run a benchmark on a generic function, with the given input vector.
 
template<typename InputType = double, typename Function >
void benchmark (const std::string &name, Function func, benchmark_options< InputType > opt)
 Run a benchmark on a generic function, with the given options.
 
template<typename InputType = double, typename Function >
void benchmark (const std::string &name, Function func, InputGenerator< InputType > inputGenerator, unsigned int runs=0, unsigned int iterations=0, bool quiet=false)
 Run a benchmark on a generic function, with the given argument options.
 
void wait_results ()
 Wait for all concurrent benchmarks to finish execution.
 
std::vector< benchmark_resultget_benchmark (const std::string &name)
 Get a list of benchmarks results associated to the given name or label.
 
benchmark_result get_benchmark (const std::string &name, unsigned int i)
 Get a benchmark result associated to the given name or label and index.
 

Public Attributes

benchmark_settings settings
 Settings for the benchmark context.
 
std::shared_ptr< output::output_contextoutput
 Output module settings for the context, dynamically allocated and possibly shared between multiple contexts.
 
std::shared_ptr< random::random_contextrandom
 Random module settings for the context, dynamically allocated and possibly shared between multiple contexts.
 

Detailed Description

Benchmark module context, handling benchmark requests concurrently.

Member Function Documentation

◆ benchmark() [1/3]

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

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

The result is registered inside 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_context::benchmark ( const std::string &  name,
Function  func,
const std::vector< InputType > &  input,
unsigned int  runs = 0,
bool  quiet = false 
)
inline

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

The result is registered inside benchmarkResults.

Parameters
nameThe name of the test case
funcThe function to benchmark
inputThe vector of input values (InputType must correspond to the argument of func, but may be any POD or aggregate data type, such as std::tuple).
runsThe number of runs with the same input (defaults to settings.defaultRuns).

◆ benchmark() [3/3]

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

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

The result is registered inside 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

◆ get_benchmark() [1/2]

std::vector< benchmark_result > chebyshev::benchmark::benchmark_context::get_benchmark ( const std::string &  name)
inline

Get a list of benchmarks results associated to the given name or label.

Note
This function waits for all previous test cases to end before returning, so it is advised to retrieve test results after all tests have been requested.

◆ get_benchmark() [2/2]

benchmark_result chebyshev::benchmark::benchmark_context::get_benchmark ( const std::string &  name,
unsigned int  i 
)
inline

Get a benchmark result associated to the given name or label and index.

Note
This function waits for all previous test cases to end before returning, so it is advised to retrieve test results after all tests have been requested.

◆ setup()

void chebyshev::benchmark::benchmark_context::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::benchmark_context::terminate ( bool  exit = false)
inline

Terminate the benchmarking environment.

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

Parameters
exitWhether to exit after terminating the module.

The documentation for this class was generated from the following file: