Skip to content

Commit

Permalink
Benchmark: include benchmark suite and automation for multiple os
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice committed Mar 11, 2022
1 parent 7825bb7 commit dd6dc23
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 1 deletion.
50 changes: 50 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on: [ push, pull_request ]

name: Benchmark

jobs:
benchmark:
name: Run benchmarks
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
steps:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: '3.7'

- uses: actions/cache@v2
with:
path: .venv
key: poetry-${{ hashFiles('poetry.lock') }}

- name: Download benchmark artifacts
uses: dawidd6/action-download-artifact@v2
with:
workflow: bench.yml
name: benchmarks-${{ matrix.os }}
path: .benchmarks
continue-on-error: true

- name: Run pytest-benchmark
run: |
. scripts/ci_install_deps
poetry run pytest benchmarks \
--benchmark-compare
--benchmark-save=main-${{ matrix.os }} \
--benchmark-warmup=on
- name: Archive benchmark results
if: ${{ github.ref == 'refs/heads/main'}}
uses: actions/upload-artifact@v3
with:
name: benchmarks-${{ matrix.os }}
path: .benchmarks
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,5 @@ fabric.properties


node_modules/

.benchmarks
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "quillang"]
path = docs/quil
url = https://github.com/rigetti/quil.git
[submodule "benchmarks/quilc"]
path = benchmarks/quilc
url = https://github.com/quil-lang/quilc.git
Empty file added benchmarks/__init__.py
Empty file.
1 change: 1 addition & 0 deletions benchmarks/quilc
Submodule quilc added at 5d69ac
29 changes: 29 additions & 0 deletions benchmarks/test_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
import os
from pyquil._parser.parser import run_parser
from pyquil.quil import Program


def from_corpus():
programs = []
dir = os.path.join(os.path.dirname(__file__), "quilc", "tests", "good-test-files")
for path in os.listdir(dir):
filepath = os.path.join(dir, path)
if os.path.isfile(filepath):
file = open(filepath, "r")
program = file.read()
try:
run_parser(program)
programs.append((path, program))
except:
continue
finally:
file.close()

return programs


@pytest.mark.parametrize("quil", from_corpus())
def test_parser(benchmark, quil):
benchmark.group = "Parse: %s" % quil[0]
benchmark((lambda: Program(run_parser(quil[1]))))
69 changes: 68 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pytest-timeout = "^1.4.2"
pytest-mock = "^3.6.1"
pytest-freezegun = "^0.4.2"
respx = "^0.15"
pytest-benchmark = "^3.4.1"

[tool.poetry.extras]
latex = ["ipython"]
Expand Down

0 comments on commit dd6dc23

Please sign in to comment.