Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3555174
commit 3751fc2
Showing
5 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ revdep | |
^tests/testmanual$ | ||
^\.pre-commit-config\.yaml$ | ||
^brew\-log$ | ||
^\.github$ | ||
^\.github/$ | ||
^bench/$ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
name: Continuous Benchmarks | ||
|
||
jobs: | ||
build: | ||
runs-on: macOS-latest | ||
steps: | ||
- name: Checkout repo | ||
with: | ||
fetch-depth: 0 | ||
uses: actions/checkout@master | ||
- name: Ensure master branch is fetched | ||
if: ${{ github.event_name == 'pull_request' }} | ||
run: git branch $GITHUB_BASE_REF remotes/origin/$GITHUB_BASE_REF; git branch | ||
- name: Setup R | ||
uses: r-lib/actions/setup-r@master | ||
- name: Query dependencies | ||
run: | | ||
install.packages('remotes') | ||
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) | ||
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") | ||
shell: Rscript {0} | ||
|
||
- name: Cache R packages | ||
if: runner.os != 'Windows' | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ env.R_LIBS_USER }} | ||
key: ${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} | ||
restore-keys: ${{ hashFiles('.github/R-version') }}-1- | ||
|
||
- name: Install dependencies | ||
run: | | ||
Rscript -e "install.packages(c('gert', 'ggplot2', 'purrr'))" -e "remotes::install_deps(dependencies = TRUE); remotes::install_github('r-lib/bench')" | ||
R CMD INSTALL . | ||
- name: Checkout benchmarking repo | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: r-lib/here | ||
ref: v0.1 | ||
path: bench/sources/here | ||
- name: Fetch existing benchmarks | ||
run: Rscript -e '#bench::cb_fetch()' | ||
- name: Run benchmarks | ||
run: Rscript -e 'bench::cb_run()' | ||
- name: Show benchmarks | ||
run: git notes --ref benchmarks show | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: visual-benchmarks | ||
path: bench/plots/ | ||
- name: Push benchmarks | ||
if: ${{ github.event_name == 'push' }} | ||
run: Rscript -e "bench::cb_push()" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#' Plot benchmarks against master, if benchmarks there exist | ||
#' | ||
#' | ||
#' @param new_bm A new benchmark object. | ||
#' @param new_bm_label The label of the new benchmark used as a title. | ||
#' @param file The file path to write the plot. | ||
plot_against_master <- function(new_bm, | ||
new_bm_label = deparse(substitute(new_bm)), | ||
file = paste0("plots/", new_bm_label, ".pdf")) { | ||
new_bm <- bench::as_bench_mark(new_bm) | ||
branches <- gert::git_branch_list() | ||
master <- branches[branches$name == "master", "commit", drop = TRUE] | ||
bm <- bench::cb_read() | ||
hash_is_master <- bm$commit_hash == master | ||
if (any(hash_is_master) && Sys.getenv("GITHUB_BASE_REF") != "") { | ||
# if a pull request | ||
reference <- bm[hash_is_master, "benchmarks"][[1]][[1]] | ||
reference$expression <- bench:::new_bench_expr(Sys.getenv("GITHUB_BASE_REF")) | ||
new_bm$expression <- bench:::new_bench_expr(Sys.getenv("GITHUB_HEAD_REF")) | ||
new_bm <- rbind(reference, new_bm) | ||
} | ||
plot <- ggplot2::ggplot(new_bm) + | ||
ggplot2::geom_boxplot(ggplot2::aes( | ||
x = name, ymin = p0, | ||
ymax = p100, lower = p25, | ||
middle = p50, upper = p75 | ||
), | ||
stat = "identity" | ||
) | ||
|
||
ggplot2::ggsave(file, plot) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# drop all notes | ||
# git update-ref -d refs/notes/benchmarks | ||
|
||
library(styler) | ||
library(magrittr) | ||
path <- "sources/here" | ||
dir.create("plots") | ||
cache_clear(ask = FALSE) | ||
cache_activate() | ||
cache_info() | ||
|
||
marker <- purrr::partial( | ||
bench::mark, | ||
min_iterations = 20, | ||
check = FALSE, | ||
filter_gc = FALSE, | ||
memory = TRUE # skip uncached first round | ||
) | ||
|
||
with_cache <- marker( | ||
with_cache = { | ||
style_pkg(path) | ||
} | ||
) | ||
cache_info() | ||
gert::git_reset("hard", repo = path) | ||
cache_deactivate() | ||
|
||
without_cache <- marker( | ||
without_cache = { | ||
style_pkg(path) | ||
} | ||
) | ||
latest_bm <- bench::cb_read()$benchmarks[[1]] | ||
split(latest_bm, latest_bm$name) %>% | ||
purrr::imap(plot_against_master) |