Performance Testing Suite for the Stan C++ libraries
- Build the project in a build directory
cmake -S . -B "build" -DCMAKE_BUILD_TYPE=Release
cd ./build
# After you are in the build file you can call `cmake ..` to re-run cmake- Compile the google bench binaries
make matmul_soa matmul_aos- Run each test saving their results to local folder. Here we use
taskset -c 0to pin the benchmark to the first cpu.
taskset -c 11 ./benchmarks/matmul_aos_soa/matmul_soa --benchmark_out_format=csv --benchmark_out=./benchmarks/matmul_aos_soa/matmul_soa.csv --benchmark_repetitions=30 --benchmark_report_aggregates_only=false
taskset -c 11 ./benchmarks/matmul_aos_soa/matmul_aos --benchmark_out_format=csv --benchmark_out=./benchmarks/matmul_aos_soa/matmul_aos.csv --benchmark_repetitions=30 --benchmark_report_aggregates_only=false- Run the script to plot the results.
Rscript ./scripts/matmul_aos_soa/plot.R- Make a new folder in
benchmarks
mkdir ./benchmarks/my_new_bench- Write your test using google benchmark
// Example benchmark
#include <benchmark/benchmark.h>
static void BM_StringCreation(benchmark::State& state) {
for (auto _ : state)
std::string empty_string;
}
// Register the function as a benchmark
BENCHMARK(BM_StringCreation);
// Define another benchmark
static void BM_StringCopy(benchmark::State& state) {
std::string x = "hello";
for (auto _ : state)
std::string copy(x);
}
BENCHMARK(BM_StringCopy);
BENCHMARK_MAIN();- Make a
CMakeLists.txtfile in your benchmark folder to compile your test
add_executable(matmul_aos aos.cpp)- In the
benchmarksfolder, add your subdirectory to theCMakeLists.txt
add_subdirectory(my_new_bench)-
From the top level directory, either call
cmake -S . -B "build" -DCMAKE_BUILD_TYPE=Releaseormkdir build; cd build; cmake .. -DCMAKE_BUILD_TYPE=Release -
cdinto build and callmake my_bench_name -
Run your benchmark, storing any scripts to generate plots in a
scripts/my_new_benchfolder
This repo comes with tbb, Eigen, sundials, boost headers, stan, and stan math which you can find in the top level CMakeLists.txt.

