Skip to content

Commit

Permalink
Add preformance testing via touchstone
Browse files Browse the repository at this point in the history
  • Loading branch information
rstub committed Apr 22, 2024
1 parent f2492c5 commit 43b718d
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 0 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
^doc$
^\.cache$
^compile_commands\.json$
^touchstone$
21 changes: 21 additions & 0 deletions .github/workflows/touchstone-comment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Continuous Benchmarks (Comment)

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

on:
workflow_run:
workflows: ["Continuous Benchmarks (Receive)"]
types:
- completed

jobs:
upload:
runs-on: ubuntu-latest
if: >
${{ github.event.workflow_run.event == 'pull_request' }}
steps:
- uses: lorenzwalthert/touchstone/actions/comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56 changes: 56 additions & 0 deletions .github/workflows/touchstone-receive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Continuous Benchmarks (Receive)

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

on:
pull_request:

jobs:
prepare:
runs-on: ubuntu-latest
if:
true &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
outputs:
config: ${{ steps.read_touchstone_config.outputs.config }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- id: read_touchstone_config
run: |
content=`cat ./touchstone/config.json`
# the following lines are only required for multi line json
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
# end of optional handling for multi line json
echo "::set-output name=config::$content"
build:
needs: prepare
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- ${{ fromJson(needs.prepare.outputs.config) }}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: lorenzwalthert/touchstone/actions/receive@v1
with:
cache-version: 1
benchmarking_repo: ${{ matrix.config.benchmarking_repo }}
benchmarking_ref: ${{ matrix.config.benchmarking_ref }}
benchmarking_path: ${{ matrix.config.benchmarking_path }}
force_upstream: true
6 changes: 6 additions & 0 deletions touchstone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!script.R
!config.json
!.gitignore
!header.R
!footer.R
8 changes: 8 additions & 0 deletions touchstone/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"os": "ubuntu-22.04",
"r": "4.3.1",
"rspm": "https://packagemanager.rstudio.com/all/__linux__/jammy/latest",
// "benchmarking_repo": "lorenzwalthert/here",
// "benchmarking_ref": "ca9c8e69c727def88d8ba1c8b85b0e0bcea87b3f",
"benchmarking_path": "touchstone/sources/here",
}
10 changes: 10 additions & 0 deletions touchstone/footer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# You can modify the PR comment footer here. You can use github markdown e.g.
# emojis like :tada:.
# This file will be parsed and evaluate within the context of
# `benchmark_analyze` and should return the comment text as the last value.
# See `?touchstone::pr_comment`
link <- "https://lorenzwalthert.github.io/touchstone/articles/inference.html"
glue::glue(
"\nFurther explanation regarding interpretation and",
" methodology can be found in the [documentation]({link})."
)
13 changes: 13 additions & 0 deletions touchstone/header.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# You can modify the PR comment header here. You can use github markdown e.g.
# emojis like :tada:.
# This file will be parsed and evaluate within the context of
# `benchmark_analyze` and should return the comment text as the last value.
# Available variables for glue substitution:
# * ci: confidence interval
# * branches: BASE and HEAD branches benchmarked against each other.
# See `?touchstone::pr_comment`
glue::glue(
"This is how benchmark results would change (along with a",
" {100 * ci}% confidence interval in relative change) if ",
"{system2('git', c('rev-parse', 'HEAD'), stdout = TRUE)} is merged into {branches[1]}:\n"
)
44 changes: 44 additions & 0 deletions touchstone/script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# see `help(run_script, package = 'touchstone')` on how to run this
# interactively

# TODO OPTIONAL Add directories you want to be available in this file or during the
# benchmarks.
# touchstone::pin_assets("some/dir")

# installs branches to benchmark
touchstone::branch_install()

# benchmark a function call from your package (two calls per branch)
touchstone::benchmark_run(
# expr_before_benchmark = source("dir/data.R"), #<-- TODO OTPIONAL setup before benchmark
runif_test = dqrng::dqrunif(1e6), #<- TODO put the call you want to benchmark here
n = 10
)

# benchmark a function call from your package (two calls per branch)
touchstone::benchmark_run(
# expr_before_benchmark = source("dir/data.R"), #<-- TODO OTPIONAL setup before benchmark
rnorm_test = dqrng::dqrnorm(1e6), #<- TODO put the call you want to benchmark here
n = 10
)

# benchmark a function call from your package (two calls per branch)
touchstone::benchmark_run(
# expr_before_benchmark = source("dir/data.R"), #<-- TODO OTPIONAL setup before benchmark
rexp_test = dqrng::dqrexp(1e6), #<- TODO put the call you want to benchmark here
n = 10
)

# TODO OPTIONAL benchmark any R expression (six calls per branch)
# touchstone::benchmark_run(
# more = {
# if (TRUE) {
# y <- yourpkg::f2(x = 3)
# }
# }, #<- TODO put the call you want to benchmark here
# n = 6
# )


# create artifacts used downstream in the GitHub Action
touchstone::benchmark_analyze()
1 change: 1 addition & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.html
*.R
*_files

0 comments on commit 43b718d

Please sign in to comment.