From 305620759e1d72059f10bf1e7251c5a3b888a91a Mon Sep 17 00:00:00 2001 From: etiennebacher Date: Wed, 23 Oct 2024 21:23:02 +0200 Subject: [PATCH] produce table instead of plot --- .github/scripts/benchmarks.R | 60 ++++++++++++++++--------------- .github/workflows/benchmarks.yaml | 3 +- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.github/scripts/benchmarks.R b/.github/scripts/benchmarks.R index 3943896fa..8bd4a11b4 100644 --- a/.github/scripts/benchmarks.R +++ b/.github/scripts/benchmarks.R @@ -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( @@ -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) @@ -34,7 +36,7 @@ out <- cross::run( # 26 variables slopes(mod), check = FALSE, - iterations = 5 + iterations = 10 ) } ) @@ -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") diff --git a/.github/workflows/benchmarks.yaml b/.github/workflows/benchmarks.yaml index e0009bf4b..58ac0e150 100644 --- a/.github/workflows/benchmarks.yaml +++ b/.github/workflows/benchmarks.yaml @@ -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} @@ -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