Created
June 11, 2020 13:10
-
-
Save bbbales2/dd93b94202b9bd2fcc79df7300d5185d to your computer and use it in GitHub Desktop.
Benchmarks
This file contains 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> | |
// Just to kick off the stack allocation | |
static void geometric_series(benchmark::State& state) { | |
using stan::math::var; | |
for (auto _ : state) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
var r = 1.0; | |
var sum = 0.0; | |
for(size_t i = 0; i < state.range(0); ++i) { | |
sum += r; | |
r = r * 0.99; | |
} | |
sum.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; | |
int end_val = 1024; | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(256, 256)->UseManualTime(); | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
BENCHMARK_MAIN(); | |
This file contains 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> | |
// Just to kick off the stack allocation | |
static void geometric_series(benchmark::State& state) { | |
using stan::math::var; | |
for (auto _ : state) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
var r = 1.0; | |
var sum = 0.0; | |
for(size_t i = 0; i < state.range(0); ++i) { | |
sum += r; | |
r = r * 0.99; | |
} | |
sum.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; | |
int end_val = 1024; | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(256, 256)->UseManualTime(); | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
BENCHMARK_MAIN(); | |
This file contains 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> | |
// Just to kick off the stack allocation | |
static void geometric_series(benchmark::State& state) { | |
using stan::math::var_value; | |
for (auto _ : state) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
var_value<Eigen::MatrixXd> r = Eigen::MatrixXd::Ones(state.range(0), 1); | |
var_value<Eigen::MatrixXd> sum = Eigen::MatrixXd::Zero(state.range(0), 1); | |
for(size_t i = 0; i < 1000; ++i) { | |
r = r * 0.99; | |
} | |
stan::math::sum(r).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(); | |
} | |
} | |
static void geometric_series_reverse(benchmark::State& state) { | |
using stan::math::var_value; | |
var_value<Eigen::MatrixXd> r = Eigen::MatrixXd::Ones(state.range(0), 1); | |
var_value<Eigen::MatrixXd> sum = Eigen::MatrixXd::Zero(state.range(0), 1); | |
for(size_t i = 0; i < 1000; ++i) { | |
r = r * 0.99; | |
} | |
var_value<double> lp = stan::math::sum(r); | |
for (auto _ : state) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
lp.grad(); | |
stan::math::set_zero_all_adjoints(); | |
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()); | |
benchmark::ClobberMemory(); | |
} | |
stan::math::recover_memory(); | |
} | |
// The start and ending sizes for the benchmark | |
int start_val = 2; | |
int end_val = 4096; | |
/*BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(1, 1)->UseManualTime();*/ | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
//BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
BENCHMARK_MAIN(); | |
This file contains 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> | |
// Just to kick off the stack allocation | |
static void geometric_series(benchmark::State& state) { | |
using stan::math::var_value; | |
for (auto _ : state) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
var_value<Eigen::MatrixXd> r = Eigen::MatrixXd::Ones(state.range(0), 1); | |
var_value<Eigen::MatrixXd> sum = Eigen::MatrixXd::Zero(state.range(0), 1); | |
for(size_t i = 0; i < 1000; ++i) { | |
r = r * 0.99; | |
} | |
stan::math::sum(r).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(); | |
} | |
} | |
static void geometric_series_reverse(benchmark::State& state) { | |
using stan::math::var_value; | |
var_value<Eigen::MatrixXd> r = Eigen::MatrixXd::Ones(state.range(0), 1); | |
var_value<Eigen::MatrixXd> sum = Eigen::MatrixXd::Zero(state.range(0), 1); | |
for(size_t i = 0; i < 1000; ++i) { | |
r = r * 0.99; | |
} | |
var_value<double> lp = stan::math::sum(r); | |
for (auto _ : state) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
lp.grad(); | |
stan::math::set_zero_all_adjoints(); | |
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()); | |
benchmark::ClobberMemory(); | |
} | |
stan::math::recover_memory(); | |
} | |
// The start and ending sizes for the benchmark | |
int start_val = 2; | |
int end_val = 4096; | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
//BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
BENCHMARK_MAIN(); | |
This file contains 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> | |
// Just to kick off the stack allocation | |
static void geometric_series(benchmark::State& state) { | |
using stan::math::var; | |
for (auto _ : state) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
Eigen::Matrix<var, -1, -1> r = Eigen::MatrixXd::Ones(state.range(0), 1); | |
Eigen::Matrix<var, -1, -1> sum = Eigen::MatrixXd::Zero(state.range(0), 1); | |
for(size_t i = 0; i < 1000; ++i) { | |
//sum = sum + r; | |
r = r * 0.99; | |
} | |
stan::math::sum(r).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(); | |
} | |
} | |
static void geometric_series_reverse(benchmark::State& state) { | |
using stan::math::var; | |
Eigen::Matrix<var, -1, -1> r = Eigen::MatrixXd::Ones(state.range(0), 1); | |
Eigen::Matrix<var, -1, -1> sum = Eigen::MatrixXd::Zero(state.range(0), 1); | |
for(size_t i = 0; i < 1000; ++i) { | |
//sum = sum + r; | |
r = r * 0.99; | |
} | |
var lp = stan::math::sum(r); | |
for (auto _ : state) { | |
auto start = std::chrono::high_resolution_clock::now(); | |
lp.grad(); | |
stan::math::set_zero_all_adjoints(); | |
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()); | |
benchmark::ClobberMemory(); | |
} | |
stan::math::recover_memory(); | |
} | |
// The start and ending sizes for the benchmark | |
int start_val = 2; | |
int end_val = 4096; | |
/*BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(1, 1)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(1, 1)->UseManualTime();*/ | |
BENCHMARK(geometric_series)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
BENCHMARK(geometric_series_reverse)->RangeMultiplier(2)->Range(start_val, end_val)->UseManualTime(); | |
//BENCHMARK(geometric_series)->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