Skip to content

Commit 43b718d

Browse files
committed
Add preformance testing via touchstone
1 parent f2492c5 commit 43b718d

9 files changed

Lines changed: 160 additions & 0 deletions

File tree

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
^doc$
2121
^\.cache$
2222
^compile_commands\.json$
23+
^touchstone$
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Continuous Benchmarks (Comment)
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.head_ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_run:
9+
workflows: ["Continuous Benchmarks (Receive)"]
10+
types:
11+
- completed
12+
13+
jobs:
14+
upload:
15+
runs-on: ubuntu-latest
16+
if: >
17+
${{ github.event.workflow_run.event == 'pull_request' }}
18+
steps:
19+
- uses: lorenzwalthert/touchstone/actions/comment@v1
20+
with:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Continuous Benchmarks (Receive)
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.head_ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
pull_request:
9+
10+
jobs:
11+
prepare:
12+
runs-on: ubuntu-latest
13+
if:
14+
true &&
15+
(
16+
github.event.comment.author_association == 'OWNER' ||
17+
github.event.comment.author_association == 'MEMBER' ||
18+
github.event.comment.author_association == 'COLLABORATOR'
19+
)
20+
outputs:
21+
config: ${{ steps.read_touchstone_config.outputs.config }}
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 0
27+
28+
- id: read_touchstone_config
29+
run: |
30+
content=`cat ./touchstone/config.json`
31+
# the following lines are only required for multi line json
32+
content="${content//'%'/'%25'}"
33+
content="${content//$'\n'/'%0A'}"
34+
content="${content//$'\r'/'%0D'}"
35+
# end of optional handling for multi line json
36+
echo "::set-output name=config::$content"
37+
build:
38+
needs: prepare
39+
runs-on: ${{ matrix.config.os }}
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
config:
44+
- ${{ fromJson(needs.prepare.outputs.config) }}
45+
env:
46+
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
47+
RSPM: ${{ matrix.config.rspm }}
48+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
49+
steps:
50+
- uses: lorenzwalthert/touchstone/actions/receive@v1
51+
with:
52+
cache-version: 1
53+
benchmarking_repo: ${{ matrix.config.benchmarking_repo }}
54+
benchmarking_ref: ${{ matrix.config.benchmarking_ref }}
55+
benchmarking_path: ${{ matrix.config.benchmarking_path }}
56+
force_upstream: true

touchstone/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!script.R
3+
!config.json
4+
!.gitignore
5+
!header.R
6+
!footer.R

touchstone/config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"os": "ubuntu-22.04",
3+
"r": "4.3.1",
4+
"rspm": "https://packagemanager.rstudio.com/all/__linux__/jammy/latest",
5+
// "benchmarking_repo": "lorenzwalthert/here",
6+
// "benchmarking_ref": "ca9c8e69c727def88d8ba1c8b85b0e0bcea87b3f",
7+
"benchmarking_path": "touchstone/sources/here",
8+
}

touchstone/footer.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# You can modify the PR comment footer here. You can use github markdown e.g.
2+
# emojis like :tada:.
3+
# This file will be parsed and evaluate within the context of
4+
# `benchmark_analyze` and should return the comment text as the last value.
5+
# See `?touchstone::pr_comment`
6+
link <- "https://lorenzwalthert.github.io/touchstone/articles/inference.html"
7+
glue::glue(
8+
"\nFurther explanation regarding interpretation and",
9+
" methodology can be found in the [documentation]({link})."
10+
)

touchstone/header.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# You can modify the PR comment header here. You can use github markdown e.g.
2+
# emojis like :tada:.
3+
# This file will be parsed and evaluate within the context of
4+
# `benchmark_analyze` and should return the comment text as the last value.
5+
# Available variables for glue substitution:
6+
# * ci: confidence interval
7+
# * branches: BASE and HEAD branches benchmarked against each other.
8+
# See `?touchstone::pr_comment`
9+
glue::glue(
10+
"This is how benchmark results would change (along with a",
11+
" {100 * ci}% confidence interval in relative change) if ",
12+
"{system2('git', c('rev-parse', 'HEAD'), stdout = TRUE)} is merged into {branches[1]}:\n"
13+
)

touchstone/script.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# see `help(run_script, package = 'touchstone')` on how to run this
2+
# interactively
3+
4+
# TODO OPTIONAL Add directories you want to be available in this file or during the
5+
# benchmarks.
6+
# touchstone::pin_assets("some/dir")
7+
8+
# installs branches to benchmark
9+
touchstone::branch_install()
10+
11+
# benchmark a function call from your package (two calls per branch)
12+
touchstone::benchmark_run(
13+
# expr_before_benchmark = source("dir/data.R"), #<-- TODO OTPIONAL setup before benchmark
14+
runif_test = dqrng::dqrunif(1e6), #<- TODO put the call you want to benchmark here
15+
n = 10
16+
)
17+
18+
# benchmark a function call from your package (two calls per branch)
19+
touchstone::benchmark_run(
20+
# expr_before_benchmark = source("dir/data.R"), #<-- TODO OTPIONAL setup before benchmark
21+
rnorm_test = dqrng::dqrnorm(1e6), #<- TODO put the call you want to benchmark here
22+
n = 10
23+
)
24+
25+
# benchmark a function call from your package (two calls per branch)
26+
touchstone::benchmark_run(
27+
# expr_before_benchmark = source("dir/data.R"), #<-- TODO OTPIONAL setup before benchmark
28+
rexp_test = dqrng::dqrexp(1e6), #<- TODO put the call you want to benchmark here
29+
n = 10
30+
)
31+
32+
# TODO OPTIONAL benchmark any R expression (six calls per branch)
33+
# touchstone::benchmark_run(
34+
# more = {
35+
# if (TRUE) {
36+
# y <- yourpkg::f2(x = 3)
37+
# }
38+
# }, #<- TODO put the call you want to benchmark here
39+
# n = 6
40+
# )
41+
42+
43+
# create artifacts used downstream in the GitHub Action
44+
touchstone::benchmark_analyze()

vignettes/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.html
22
*.R
3+
*_files

0 commit comments

Comments
 (0)