|
| 1 | +# see `help(run_script, package = 'touchstone')` on how to run this |
| 2 | +# interactively |
| 3 | + |
| 4 | +# installs branches to benchmark |
| 5 | +touchstone::branch_install() |
| 6 | + |
| 7 | +touchstone::pin_assets("touchstone/wine.rds") |
| 8 | + |
| 9 | +# These synthetic workloads are large enough to expose real slowdowns in the |
| 10 | +# core `loo()` paths, but still short enough to keep PR feedback reasonably fast. |
| 11 | +touchstone::benchmark_run( |
| 12 | + expr_before_benchmark = { |
| 13 | + suppressPackageStartupMessages(library(loo)) |
| 14 | + # benchmark_run() evaluates in a callr subprocess, so load pinned assets here. |
| 15 | + wine_log_lik_matrix <- readRDS(touchstone::path_pinned_asset( |
| 16 | + "touchstone/wine.rds" |
| 17 | + )) |
| 18 | + matrix_r_eff <- rep(1, ncol(wine_log_lik_matrix)) |
| 19 | + }, |
| 20 | + loo_matrix = { |
| 21 | + suppressWarnings( |
| 22 | + loo( |
| 23 | + wine_log_lik_matrix, |
| 24 | + r_eff = matrix_r_eff, |
| 25 | + cores = 1 |
| 26 | + ) |
| 27 | + ) |
| 28 | + }, |
| 29 | + n = 10 |
| 30 | +) |
| 31 | + |
| 32 | +touchstone::benchmark_run( |
| 33 | + expr_before_benchmark = { |
| 34 | + suppressPackageStartupMessages(library(loo)) |
| 35 | + wine_log_lik_matrix <- readRDS(touchstone::path_pinned_asset( |
| 36 | + "touchstone/wine.rds" |
| 37 | + )) |
| 38 | + function_r_eff <- rep(1, ncol(wine_log_lik_matrix)) |
| 39 | + wine_data <- data.frame(obs = seq_len(ncol(wine_log_lik_matrix))) |
| 40 | + wine_llfun <- function(data_i, draws) draws[, data_i$obs, drop = FALSE] |
| 41 | + }, |
| 42 | + loo_function = { |
| 43 | + suppressWarnings( |
| 44 | + loo( |
| 45 | + wine_llfun, |
| 46 | + data = wine_data, |
| 47 | + draws = wine_log_lik_matrix, |
| 48 | + r_eff = function_r_eff, |
| 49 | + cores = 1 |
| 50 | + ) |
| 51 | + ) |
| 52 | + }, |
| 53 | + n = 10 |
| 54 | +) |
| 55 | + |
| 56 | +# create artifacts used downstream in the GitHub Action |
| 57 | +touchstone::benchmark_analyze() |
0 commit comments