Created
October 8, 2020 21:30
-
-
Save SteveBronder/db1309ca009578a7447e3d1c3a3f65e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <benchmark/benchmark.h> | |
#include <stan/math.hpp> | |
#include <utility> | |
#include "toss_me.hpp" | |
#include "callback_bench_impl.hpp" | |
static void tcrossprod(benchmark::State& state) { | |
using stan::math::var; | |
using stan::math::promote_scalar; | |
using stan::math::tcrossprod; | |
using stan::math::sum; | |
Eigen::MatrixXd x_val = Eigen::MatrixXd::Random(state.range(0), state.range(0)); | |
for (auto _ : state) { | |
var lp = 0; | |
auto start = std::chrono::high_resolution_clock::now(); | |
{ | |
auto x = promote_scalar<var>(x_val); | |
auto x_cross = tcrossprod(x); | |
lp += sum(x_cross); | |
} | |
lp.grad(); | |
auto end = std::chrono::high_resolution_clock::now(); | |
auto elapsed_seconds = | |
std::chrono::duration_cast<std::chrono::duration<double>>(end - start); | |
state.SetIterationTime(elapsed_seconds.count()); | |
stan::math::recover_memory(); | |
benchmark::ClobberMemory(); | |
} | |
} | |
// The start and ending sizes for the benchmark | |
int start_val = 2; | |
constexpr int end_val = 4096; | |
constexpr int extra_alloc = 4096 * 1.2; | |
BENCHMARK_TEMPLATE(toss_me, extra_alloc); | |
BENCHMARK(tcrossprod)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
BENCHMARK_MAIN(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment