Skip to content

Commit c18c149

Browse files
committed
Workflow for ASV Benchmarks in PR
1 parent 7863f8e commit c18c149

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Benchmark PR
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
permissions:
8+
contents: read # Read access for repository contents
9+
pull-requests: write # Write access for pull requests
10+
11+
env:
12+
PYTHON_VERSION: "3.10"
13+
WORKING_DIR: ${{ github.workspace }}/benchmarks
14+
15+
jobs:
16+
benchmark-pr:
17+
runs-on: ubuntu-latest
18+
19+
defaults:
20+
run:
21+
working-directory: ${{ env.WORKING_DIR }}
22+
23+
steps:
24+
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up Python
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: ${{ env.PYTHON_VERSION }}
34+
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install asv virtualenv lf-asv-formatter
39+
40+
- name: Create ASV machine config file
41+
run: asv machine --machine gh-runner --yes
42+
43+
- name: Save comparison of PR against main branch
44+
run: |
45+
# prepare main branch for comparison
46+
git remote add upstream https://github.com/${{ github.repository }}.git
47+
git fetch upstream main
48+
49+
# Run benchmarks, writing comment contents to ./output
50+
asv continuous upstream/main HEAD \
51+
--factor 1.1 --sort ratio --split --interleave-rounds -a repeat=7
52+
asv compare upstream/main HEAD --factor 1.1 --sort ratio --split | tee output
53+
python -m lf_asv_formatter --asv_version "$(echo asv --version)"
54+
printf "Benchmark Suite Results:\n\n" >> comment_body
55+
cat output >> comment_body
56+
57+
# from https://github.com/hombit/load_ztfdr_for_tape/blob/9acf7c83/.github/workflows/asv-pr.yml
58+
- name: Find benchmarks comment
59+
uses: peter-evans/find-comment@v2
60+
id: find-comment
61+
with:
62+
issue-number: ${{ github.event.pull_request.number }}
63+
comment-author: 'github-actions[bot]'
64+
body-includes: Benchmark Suite Results
65+
66+
- name: Create or update benchmarks comment
67+
uses: peter-evans/create-or-update-comment@v3
68+
with:
69+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
70+
issue-number: ${{ github.event.pull_request.number }}
71+
body-path: ${{ env.WORKING_DIR }}/comment_body
72+
edit-mode: replace

benchmarks/__init__.py

Whitespace-only changes.

benchmarks/asv.conf.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": 1,
3+
"project": "Outlines",
4+
"project_url": "https://outlines-dev.github.io/outlines/",
5+
"repo": "..",
6+
"branches": [
7+
"HEAD"
8+
],
9+
"build_command": [
10+
"python -m build -Cbuilddir=builddir --wheel --outdir {build_cache_dir} {build_dir}"
11+
],
12+
"environment_type": "virtualenv",
13+
"show_commit_url": "https://github.com/lapp0/outlines/commit/",
14+
"benchmark_dir": ".",
15+
"env_dir": "env",
16+
"results_dir": "results",
17+
"html_dir": "html",
18+
"build_cache_size": 8
19+
}

benchmarks/hello_world.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Write the benchmarking functions here.
2+
# See "Writing benchmarks" in the asv docs for more information.
3+
4+
5+
class TimeSuite:
6+
"""
7+
An example benchmark that times the performance of various kinds
8+
of iterating over dictionaries in Python.
9+
"""
10+
11+
def setup(self):
12+
self.d = {}
13+
for x in range(500):
14+
self.d[x] = None
15+
16+
def time_keys(self):
17+
for key in self.d.keys():
18+
pass
19+
20+
def time_values(self):
21+
for value in self.d.values():
22+
pass
23+
24+
def time_range(self):
25+
d = self.d
26+
for key in range(500):
27+
d[key]
28+
29+
30+
class MemSuite:
31+
def mem_list(self):
32+
return [0] * 256

0 commit comments

Comments
 (0)