Skip to content

Commit f81ff7a

Browse files
Merge pull request #698 from lorenzwalthert/touchstone
- Switch to lorenzwalthert/touchstone (#698).
2 parents 26f9f59 + 933e176 commit f81ff7a

File tree

5 files changed

+81
-141
lines changed

5 files changed

+81
-141
lines changed

.github/workflows/benchmarking.yaml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ jobs:
2121
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
2222
steps:
2323
- name: Checkout repo
24+
uses: actions/checkout@v2
2425
with:
25-
fetch-depth: 0
26-
uses: actions/checkout@master
26+
fetch-depth: 0
2727
- name: Set up git user
2828
run: |
2929
git config --local user.name "GitHub Actions"
3030
git config --local user.email "[email protected]"
3131
- name: Ensure base branch is fetched
3232
if: ${{ github.event_name == 'pull_request' }}
33-
run: git branch $GITHUB_BASE_REF remotes/origin/$GITHUB_BASE_REF; git branch
33+
run: |
34+
git checkout -b $GITHUB_HEAD_REF
35+
git branch $GITHUB_BASE_REF remotes/origin/$GITHUB_BASE_REF
3436
- name: Setup R
3537
uses: r-lib/actions/setup-r@master
3638
- name: Query dependencies
@@ -57,39 +59,33 @@ jobs:
5759
sudo apt-get install libcurl4-openssl-dev libgit2-dev
5860
- name: Install dependencies
5961
run: |
60-
Rscript -e "install.packages(c('gert', 'ggplot2', 'purrr'))" -e "remotes::install_deps(dependencies = TRUE); remotes::install_github('r-lib/bench')"
62+
Rscript -e "install.packages(c('ggplot2', 'purrr'))" -e "remotes::install_deps(dependencies = TRUE); remotes::install_github(c('r-lib/bench', 'lorenzwalthert/touchstone')); "
6163
R CMD INSTALL .
6264
- name: Checkout benchmarking repo
6365
uses: actions/checkout@v2
6466
with:
6567
repository: lorenzwalthert/here
6668
ref: ca9c8e69c727def88d8ba1c8b85b0e0bcea87b3f
67-
path: bench/sources/here
68-
- name: Fetch existing benchmarks
69-
run: Rscript -e 'rlang::with_handlers(bench::cb_fetch(), error = function(e) paste("Could not fetch benchmarks, skipping. The error was", conditionMessage(e)))'
69+
path: touchstone/sources/here
7070
- name: Prepare PR comment
7171
run: |
72-
mkdir -p bench/pr-comment
73-
echo "Here is how the current PR would change benchmark results when merged into $GITHUB_BASE_REF:" > bench/pr-comment/info.txt
74-
echo "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" >> bench/pr-comment/info.txt
72+
mkdir -p touchstone/sources
73+
mkdir -p touchstone/pr-comment
74+
mkdir -p touchstone/plots
75+
echo "Here is how the current PR would change benchmark results when merged into $GITHUB_BASE_REF:" > touchstone/pr-comment/info.txt
76+
echo "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" >> touchstone/pr-comment/info.txt
7577
- name: Run benchmarks
76-
run: Rscript -e 'bench::cb_run()'
77-
- name: Show benchmarks
78-
run: git notes --ref benchmarks show
78+
run: Rscript 'touchstone/script.R'
7979
- uses: actions/upload-artifact@v2
8080
with:
8181
name: visual-benchmarks
82-
path: bench/plots/
83-
- name: Push benchmarks
84-
if: ${{ github.event_name == 'push' }}
85-
run: Rscript -e "bench::cb_push()"
82+
path: touchstone/plots/
8683
- uses: actions/upload-artifact@v1
8784
with:
8885
name: results
89-
path: bench/pr-comment
86+
path: touchstone/pr-comment
9087
- uses: actions/download-artifact@v1
9188
with:
9289
name: results
9390
- name: comment PR
94-
#uses: machine-learning-apps/pr-comment@master
95-
run: cat bench/pr-comment/info.txt
91+
run: cat touchstone/pr-comment/info.txt

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ R/scratch
1111
revdep/
1212
!revdep/*.md
1313
!revdep/problems.md
14+
touchstone/*
15+
!touchstone/script.R

bench/01-declarations.R

Lines changed: 0 additions & 47 deletions
This file was deleted.

bench/02-basic.R

Lines changed: 0 additions & 74 deletions
This file was deleted.

touchstone/script.R

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# touchstone:::touchstone_clear() # deletes itself and sources
2+
refs <- c(Sys.getenv("GITHUB_BASE_REF", "touchstone"), Sys.getenv("GITHUB_HEAD_REF", "touchstone"))
3+
4+
timer <- purrr::partial(touchstone::benchmark_run_ref,
5+
refs = refs, n = 10
6+
)
7+
8+
styler::cache_clear()
9+
10+
timer(
11+
expr_before_benchmark = c("library(styler)", "cache_deactivate()"),
12+
without_cache = 'style_pkg("touchstone/sources/here", filetype = c("R", "rmd"))'
13+
)
14+
15+
styler::cache_clear()
16+
17+
timer(
18+
expr_before_benchmark = c("library(styler)", "cache_activate()"),
19+
cache_applying = 'style_pkg("touchstone/sources/here", filetype = c("R", "rmd"))'
20+
)
21+
22+
styler::cache_clear()
23+
24+
timer(
25+
expr_before_benchmark = c(
26+
"library(styler)",
27+
"cache_activate()"
28+
),
29+
cache_recording = c(
30+
"gert::git_reset_hard(repo = 'touchstone/sources/here')",
31+
'style_pkg("touchstone/sources/here", filetype = c("R", "rmd"))'
32+
)
33+
)
34+
35+
styler::cache_clear()
36+
37+
38+
39+
for (benchmark in touchstone::benchmark_ls()) {
40+
timings <- touchstone::benchmark_read(benchmark, refs)
41+
42+
library(ggplot2)
43+
library(magrittr)
44+
timings %>%
45+
ggplot(aes(x = elapsed, color = ref)) +
46+
geom_density()
47+
fs::path("touchstone/plots/", benchmark) %>%
48+
fs::path_ext_set("png") %>%
49+
ggsave()
50+
51+
tbl <- timings %>%
52+
dplyr::group_by(.data$ref) %>%
53+
dplyr::summarise(m = mean(.data$elapsed)) %>%
54+
tibble::deframe()
55+
56+
diff_percent <- round(100 * (tbl[refs[2]] - tbl[refs[1]]) / tbl[refs[1]], 1)
57+
cat(
58+
glue::glue("{benchmark}: {round(tbl[refs[1]], 2)} -> {round(tbl[refs[2]], 2)} ({diff_percent}%)"),
59+
fill = TRUE,
60+
file = "touchstone/pr-comment/info.txt",
61+
append = TRUE
62+
)
63+
}

0 commit comments

Comments
 (0)