Skip to content

Commit fc660f7

Browse files
committed
Benchmark: include benchmark suite and automation for multiple os
1 parent 7825bb7 commit fc660f7

File tree

8 files changed

+153
-1
lines changed

8 files changed

+153
-1
lines changed

.github/workflows/bench.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on: [ push, pull_request ]
2+
3+
name: Benchmark
4+
5+
jobs:
6+
benchmark:
7+
name: Run benchmarks
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [ubuntu-latest, macOS-latest]
12+
steps:
13+
- name: Checkout sources
14+
uses: actions/checkout@v2
15+
with:
16+
submodules: recursive
17+
18+
- name: Set up Python 3.7
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: '3.7'
22+
23+
- uses: actions/cache@v2
24+
with:
25+
path: .venv
26+
key: poetry-${{ hashFiles('poetry.lock') }}
27+
28+
- name: Download benchmark artifacts
29+
uses: dawidd6/action-download-artifact@v2
30+
with:
31+
workflow: bench.yml
32+
name: benchmarks-${{ matrix.os }}
33+
path: .benchmarks
34+
continue-on-error: true
35+
36+
- name: Run pytest-benchmark
37+
run: |
38+
. scripts/ci_install_deps
39+
poetry run pytest benchmarks \
40+
--benchmark-compare \
41+
--benchmark-save=main-${{ matrix.os }} \
42+
--benchmark-warmup=on
43+
44+
- name: Archive benchmark results
45+
if: ${{ github.ref == 'refs/heads/main'}}
46+
uses: actions/upload-artifact@v3
47+
with:
48+
name: benchmarks-${{ matrix.os }}
49+
path: .benchmarks

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,5 @@ fabric.properties
188188

189189

190190
node_modules/
191+
192+
.benchmarks

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "quillang"]
22
path = docs/quil
33
url = https://github.com/rigetti/quil.git
4+
[submodule "benchmarks/quilc"]
5+
path = benchmarks/quilc
6+
url = https://github.com/quil-lang/quilc.git

benchmarks/__init__.py

Whitespace-only changes.

benchmarks/quilc

Submodule quilc added at 5d69ac5

benchmarks/test_parser.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
import os
3+
from pyquil._parser.parser import run_parser
4+
from pyquil.quil import Program
5+
6+
7+
def from_corpus():
8+
programs = []
9+
dir = os.path.join(os.path.dirname(__file__), "quilc", "tests", "good-test-files")
10+
for path in os.listdir(dir):
11+
filepath = os.path.join(dir, path)
12+
if os.path.isfile(filepath):
13+
file = open(filepath, "r")
14+
program = file.read()
15+
try:
16+
run_parser(program)
17+
programs.append((path, program))
18+
except:
19+
continue
20+
finally:
21+
file.close()
22+
23+
return programs
24+
25+
26+
@pytest.mark.parametrize("quil", from_corpus())
27+
def test_parser(benchmark, quil):
28+
benchmark.group = "Parse: %s" % quil[0]
29+
benchmark((lambda: Program(run_parser(quil[1]))))

poetry.lock

Lines changed: 68 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pytest-timeout = "^1.4.2"
5252
pytest-mock = "^3.6.1"
5353
pytest-freezegun = "^0.4.2"
5454
respx = "^0.15"
55+
pytest-benchmark = "^3.4.1"
5556

5657
[tool.poetry.extras]
5758
latex = ["ipython"]

0 commit comments

Comments
 (0)