Skip to content

Commit 1f59b3b

Browse files
loop
1 parent 482031a commit 1f59b3b

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

touchstone/script.R

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
# touchstone:::touchstone_clear() # deletes itself and sources
2-
refs <- c(Sys.getenv("GITHUB_BASE_REF"), Sys.getenv("GITHUB_HEAD_REF"))
3-
warning(refs)
4-
timings <- touchstone::benchmark_run_ref(
5-
refs,
6-
expr_before_benchmark = c("library(styler)", "cache_deactivate()"),
7-
expr_to_benchmark = 'style_pkg("touchstone/sources/here", filetype = c("R", "rmd"))',
8-
n = 10,
2+
refs <- c(Sys.getenv("GITHUB_BASE_REF", "touchstone"), Sys.getenv("GITHUB_HEAD_REF", "touchstone"))
3+
exprs_to_benchmark <- list(
4+
cache_applying = 'style_pkg("touchstone/sources/here", filetype = c("R", "rmd"))'
95
)
6+
for (benchmark in names(exprs_to_benchmark)) {
7+
timings <- touchstone::benchmark_run_ref(
8+
refs,
9+
expr_before_benchmark = c("library(styler)", "cache_deactivate()"),
10+
!!!exprs_to_benchmark[[benchmark]],
11+
n = 10
12+
)
1013

11-
timings <- touchstone::benchmark_read(refs)
14+
timings <- touchstone::benchmark_read(benchmark, refs[1])
1215

13-
library(ggplot2)
14-
library(magrittr)
15-
timings %>%
16-
ggplot(aes(x = elapsed, color = ref)) +
17-
geom_density()
16+
library(ggplot2)
17+
library(magrittr)
18+
timings %>%
19+
ggplot(aes(x = elapsed, color = ref)) +
20+
geom_density()
21+
fs::path("touchstone/plots/", benchmark) %>%
22+
fs::path_ext_set("png") %>%
23+
ggsave()
1824

19-
ggsave("touchstone/plots/density.png")
25+
tbl <- timings %>%
26+
dplyr::group_by(.data$ref) %>%
27+
dplyr::summarise(m = mean(.data$elapsed)) %>%
28+
tibble::deframe()
2029

21-
tbl <- timings %>%
22-
dplyr::group_by(.data$ref) %>%
23-
dplyr::summarise(m = mean(.data$elapsed)) %>%
24-
tibble::deframe()
25-
26-
diff_percent <- round(100 * (tbl[refs[2]] - tbl[refs[1]]) / tbl[refs[1]], 1)
27-
writeLines(glue::glue("{round(tbl[refs[1]], 2)} -> {round(tbl[refs[2]], 2)} ({diff_percent}%)"), "touchstone/pr-comment/info.txt")
30+
diff_percent <- round(100 * (tbl[refs[2]] - tbl[refs[1]]) / tbl[refs[1]], 1)
31+
cat(
32+
glue::glue("{benchmark}: round(tbl[refs[1]], 2)} -> {round(tbl[refs[2]], 2)} ({diff_percent}%)"),
33+
file = "touchstone/pr-comment/info.txt",
34+
append = TRUE
35+
)
36+
}

0 commit comments

Comments
 (0)