ComPPare 1.0.0
Loading...
Searching...
No Matches
comppare::plugin::google_benchmark::google_benchmark_manager Class Reference

Manager class for Google Benchmark integration. More...

#include <google_benchmark.hpp>

Collaboration diagram for comppare::plugin::google_benchmark::google_benchmark_manager:
[legend]

Public Member Functions

 google_benchmark_manager ()=default
 
 ~google_benchmark_manager ()=default
 
void initialize (int &argc, char **argv)
 Initialize the Google Benchmark library.
 
template<typename Func , typename... Args>
benchmark::internal::Benchmark * add_gbench (const char *name, Func f, Args &&...args)
 Register a benchmark function with Google Benchmark.
 
void run ()
 Run the registered benchmarks.
 

Private Member Functions

void print_benchmark_header ()
 Print the benchmark header.
 

Private Attributes

int gbench_argc
 
char ** gbench_argv
 
comppare::plugin::PluginArgParser gbench_parser_ {"--gbench"}
 Argument parser for Google Benchmark.
 

Detailed Description

Manager class for Google Benchmark integration.

This class handles the initialization, registration, and execution of benchmarks using the Google Benchmark library. It provides methods to initialize the library with command-line arguments, register benchmark functions, and run the benchmarks.

Constructor & Destructor Documentation

◆ google_benchmark_manager()

comppare::plugin::google_benchmark::google_benchmark_manager::google_benchmark_manager ( )
default

◆ ~google_benchmark_manager()

comppare::plugin::google_benchmark::google_benchmark_manager::~google_benchmark_manager ( )
default

Member Function Documentation

◆ add_gbench()

template<typename Func , typename... Args>
benchmark::internal::Benchmark * comppare::plugin::google_benchmark::google_benchmark_manager::add_gbench ( const char *  name,
Func  f,
Args &&...  args 
)
inline

Register a benchmark function with Google Benchmark.

Template Parameters
FuncThe type of the benchmark function.
ArgsThe types of the arguments to the benchmark function.
Parameters
nameThe name of the benchmark.
fThe function/implementation to register.
argsThe arguments to pass to the benchmark function.
Returns
A pointer to the registered benchmark.

This helper simplifies registering a benchmark by automatically wrapping the provided function and its arguments into a Google Benchmark-compatible lambda. The lambda sets the current benchmark state and invokes the function with the captured arguments.

Usage example:

void saxpy(int n, float a, const float* x, float* y);
// Register benchmark: equivalent to writing a manual BM_ function
add_gbench("SAXPY", saxpy, 1<<20, 2.0f, x_data, y_data);
benchmark::internal::Benchmark * add_gbench(const char *name, Func f, Args &&...args)
Register a benchmark function with Google Benchmark.
Definition google_benchmark.hpp:158

This is equivalent to writing a manual Google Benchmark function:

static void BM_SAXPY(benchmark::State& st) {
for (auto _ : st) {
saxpy(1<<20, 2.0f, x_data, y_data);
}
}
BENCHMARK(BM_SAXPY);

◆ initialize()

void comppare::plugin::google_benchmark::google_benchmark_manager::initialize ( int &  argc,
char **  argv 
)
inline

Initialize the Google Benchmark library.

Parameters
argcThe number of command-line arguments.
argvThe command-line arguments.

This function initializes the Google Benchmark library with the provided command-line arguments. It also prints the benchmark header and recognized arguments to the console.

◆ print_benchmark_header()

void comppare::plugin::google_benchmark::google_benchmark_manager::print_benchmark_header ( )
inlineprivate

Print the benchmark header.

◆ run()

void comppare::plugin::google_benchmark::google_benchmark_manager::run ( )
inline

Run the registered benchmarks.

This function runs all benchmarks that have been registered with the Google Benchmark library. It should be called after all benchmarks have been registered and the library has been initialized.

Member Data Documentation

◆ gbench_argc

int comppare::plugin::google_benchmark::google_benchmark_manager::gbench_argc
private

◆ gbench_argv

char** comppare::plugin::google_benchmark::google_benchmark_manager::gbench_argv
private

◆ gbench_parser_

comppare::plugin::PluginArgParser comppare::plugin::google_benchmark::google_benchmark_manager::gbench_parser_ {"--gbench"}
private

Argument parser for Google Benchmark.


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