Skip to content

Commit

Permalink
produce table instead of plot
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Oct 23, 2024
1 parent 09acbe1 commit 3056207
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
60 changes: 31 additions & 29 deletions .github/scripts/benchmarks.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
library(dplyr)
library(ggplot2)
library(tidyr)
library(tinytable)

# Stored in the Github actions workflow
pr_number <- Sys.getenv("PR_NUMBER")
# pr_number <- 1244

out <- cross::run(
pkgs = c(
Expand All @@ -16,7 +17,8 @@ out <- cross::run(
library(data.table)

bench::press(
N = c(100, 500, 1000, 10000, 50000),
N = 50,
# N = c(100, 500, 1000, 10000, 50000),
{
dat <- data.frame(matrix(rnorm(N * 26), ncol = 26))
mod <- lm(X1 ~ ., dat)
Expand All @@ -34,7 +36,7 @@ out <- cross::run(
# 26 variables
slopes(mod),
check = FALSE,
iterations = 5
iterations = 10
)
}
)
Expand All @@ -51,32 +53,32 @@ unnested <- out |>
)
) |>
unnest(result) |>
mutate(expression = as.character(expression))
mutate(
expression = as.character(expression),
# Get duration in seconds
median = round(as.numeric(median), 3),
# Get memory in MB
mem_alloc = round(as.numeric(mem_alloc) / 1000000, 3)
) |>
select(pkg, expression, median, mem_alloc)

plot_result <- ggplot(unnested, aes(N, median, color = pkg, linetype = pkg)) +
geom_line() +
geom_point() +
facet_wrap(
~expression,
labeller = labeller(expression = label_wrap_gen(width = 25)),
scales = "free_y"
) +
labs(
y = "Median time (s)",
color = "Package version",
linetype = "Package version"
) +
theme_light() +
theme(
strip.text = element_text(color = "white", size = 10),
strip.background = element_rect(
fill = "#24478f", linetype = "solid",
color = "black", linewidth = 1
),
legend.position = "bottom"
final <- unnested |>
pivot_wider(
id_cols = expression,
names_from = pkg,
values_from = c(median, mem_alloc)
) |>
mutate(
median_diff_main_pr = round((median_PR - median_main) / median_main * 100, 2),
median_PR = paste0(median_PR, " (", median_diff_main_pr, "%)"),
mem_alloc_diff_main_pr = round((mem_alloc_PR - mem_alloc_main) / mem_alloc_main * 100, 2),
mem_alloc_PR = paste0(mem_alloc_PR, " (", mem_alloc_diff_main_pr, "%)")
) |>
select(
Expression = expression,
`Median time with PR (% change with main)` = median_PR,
`Memory used with PR (% change with main)` = mem_alloc_PR
)

ggsave(
plot = plot_result,
".github/scripts/benchmark_result.png"
)
tt(final) |>
save_tt("report.md")
3 changes: 1 addition & 2 deletions .github/workflows/benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Install required dependencies for benchmark
run: |
install.packages(c("remotes", "bench", "dplyr", "tidyr", "ggplot2"))
install.packages(c("remotes", "bench", "dplyr", "tidyr"))
remotes::install_github("DavisVaughan/cross")
shell: Rscript {0}

Expand All @@ -60,7 +60,6 @@ jobs:
- name: Push generated plot as a GH-bot comment
run: |
# Comment contents:
echo "[![Comparison Plot](./.github/scripts/benchmark_result.png)](./.github/scripts/benchmark_result.png)" >> report.md
echo -e "\nGenerated via commit ${{ github.event.pull_request.head.sha }}" >> report.md
echo -e "\nDownload link for the artifact containing the test results: [↓ benchmark-results.zip](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }})" >> report.md
cml comment update report.md
Expand Down

0 comments on commit 3056207

Please sign in to comment.