diff --git a/benchmark/Simple.cpp b/benchmark/Simple.cpp index fb1a17ae9..347e2c2cf 100644 --- a/benchmark/Simple.cpp +++ b/benchmark/Simple.cpp @@ -55,5 +55,38 @@ static void BM_ReverseModeSumExecute(benchmark::State &state) { } BENCHMARK(BM_ReverseModeSumExecute); +// Benchmark computing gradient using vector forward mode via +// CladFunction::execute. +static void BM_VectorForwardModeSumExecute(benchmark::State &state) { + auto vm_grad = clad::differentiate(sum, "p"); + double inputs[] = {1, 2, 3, 4, 5}; + double result[3] = {}; + clad::array_ref result_ref(result, 3); + unsigned long long sum = 0; + for (auto _ : state) { + vm_grad.execute(inputs,/*dim*/ 3, result_ref); + benchmark::DoNotOptimize(sum += result[0] + result[1] + result[2]); + } +} +BENCHMARK(BM_VectorForwardModeSumExecute); + +// Benchmark computing gradient using vector forward mode via +// a forward declaration. +inline void sum_dvec_0(double*, int, clad::array_ref); +static void BM_VectorForwardModeSumFwdDecl(benchmark::State &state) { + auto vm_grad = clad::differentiate(sum, "p"); + (void) vm_grad; + double inputs[] = {1, 2, 3, 4, 5}; + double result[3] = {}; + clad::array_ref result_ref(result, 3); + unsigned long long sum = 0; + for (auto _ : state) { + sum_dvec_0(inputs,/*dim*/ 3, result_ref); + benchmark::DoNotOptimize(sum += result[0] + result[1] + result[2]); + } +} +BENCHMARK(BM_VectorForwardModeSumFwdDecl); + + // Define our main. BENCHMARK_MAIN();