The benchmark class. More...
#include <Benchmark.hpp>
Public Member Functions | |
Benchmark (std::string n) | |
void | setValue (S val) |
Set the value for the benchmark. | |
S | getValue () const |
Get the value for the current run of the benchmark. | |
virtual void | preBench () |
The pre benchmark task. | |
virtual void | bench ()=0 |
the benchmark function. | |
virtual void | postBench () |
the post benchmark function. | |
std::string | getName () const |
Get the name of the benchmark. | |
void | setName (std::string n) |
Set the name of the benchmark. | |
BenchResult | run (unsigned repeats, unsigned warmup) |
run the benchmark. |
The benchmark class.
All benchmarks using this framework should inherit from this base class.
virtual void Benchmark< S >::bench | ( | ) | [pure virtual] |
the benchmark function.
This is the function that is timed when running the benchmark.
std::string Benchmark< S >::getName | ( | ) | const [inline] |
Get the name of the benchmark.
S Benchmark< S >::getValue | ( | ) | const [inline] |
Get the value for the current run of the benchmark.
The value could potentially be updated before each time the bench function is called. This function is the correct way to get the current value to use as input to the benchmark.
virtual void Benchmark< S >::postBench | ( | ) | [inline, virtual] |
the post benchmark function.
This should take care of any cleanup required for the benchmark to be run again. It should return the benchmark back to its original state, as the same benchmark object will be used for multiple runs.
virtual void Benchmark< S >::preBench | ( | ) | [inline, virtual] |
The pre benchmark task.
Sometimes benchmarks require tasks to be done before the code that you're interested in benchmarking. This is the place to take care of that. The runtime if this function will not be included in the total benchmark runtime.
BenchResult Benchmark< S >::run | ( | unsigned | repeats, |
unsigned | warmup | ||
) |
run the benchmark.
repeats | The number of times to repeat the benchmark. |
warmup | The number of times to run the benchmark before beginning timing. |
Run this benchmark the number of times given by repeats. After it's done running, it will find the average runtime and the standard deviation of the runtimes. The information will be returned in a BenchResult object.
void Benchmark< S >::setName | ( | std::string | n ) | [inline] |
Set the name of the benchmark.
n | std::string the name. |
void Benchmark< S >::setValue | ( | S | val ) | [inline] |
Set the value for the benchmark.
val | S the value. |
This can really be anything, but should be able to be taken as input to the std::stringstream left-shift operator.