Skip to content

Commit

Permalink
Run benchmarks as unit tests on CI (#61)
Browse files Browse the repository at this point in the history
* Run benchmarks as unit tests on CI

* Run cargo test with --release for linux and pypy jobs

* Fix test_cramjam_snappy_de_compress_into
  • Loading branch information
messense authored May 31, 2021
1 parent 0f79b0a commit f9665a0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
- name: Build
run: cargo build --release
- name: Tests
run: cargo test --no-default-features
run: cargo test --no-default-features --release
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -139,6 +139,12 @@ jobs:
run: |
pip uninstall numpy -y
python -m pytest tests/test_no_numpy.py
- name: Test benchmarks
if: matrix.target == 'x86_64'
run: |
sudo apt-get install -y libsnappy-dev
pip install -r benchmark-requirements.txt
make test-bench
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -211,7 +217,7 @@ jobs:
- name: Build
run: cargo build --release
- name: Tests
run: cargo test --no-default-features
run: cargo test --no-default-features --release
- uses: actions/setup-python@v2
with:
python-version: pypy-3.6
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ BASE_BENCH_CMD = python -m pytest -v --benchmark-sort name --benchmark-only benc
test:
python -m pytest tests -v --ignore benchmarks

test-bench:
python -m pytest -v --benchmark-disable benchmarks/

bench:
python -m pytest -v --benchmark-only --benchmark-sort name benchmarks/

Expand Down
2 changes: 2 additions & 0 deletions benchmark-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ python-snappy==0.5.4
lz4==3.1.0
brotlipy==0.7.0
zstd==1.4.5.1
numpy
memory-profiler
15 changes: 11 additions & 4 deletions benchmarks/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_snappy_framed(benchmark, file, use_cramjam: bool):
)


@pytest.mark.parametrize("op", ("decompress_raw_into", "compress_raw_into"))
@pytest.mark.parametrize("op", ("decompress_into", "compress_into"))
@pytest.mark.parametrize("file", FILES, ids=lambda val: val.name)
def test_cramjam_snappy_de_compress_into(benchmark, op, file):
"""
Expand All @@ -110,7 +110,8 @@ def test_cramjam_snappy_de_compress_into(benchmark, op, file):

operation = getattr(snappy, op)
buffer = np.zeros(
len(data) if op == "decompress_into" else len(compressed_data), dtype=np.uint8
len(data) if op == "decompress_into" else len(compressed_data),
dtype=np.uint8,
)

benchmark(
Expand Down Expand Up @@ -187,7 +188,10 @@ def test_lz4_block(benchmark, file, use_cramjam: bool):
)
else:
benchmark(
round_trip, compress=block.compress, decompress=block.decompress, data=data,
round_trip,
compress=block.compress,
decompress=block.decompress,
data=data,
)


Expand Down Expand Up @@ -240,7 +244,10 @@ def test_zstd(benchmark, file, use_cramjam: bool):
)
else:
benchmark(
round_trip, compress=zstd.compress, decompress=zstd.decompress, data=data,
round_trip,
compress=zstd.compress,
decompress=zstd.decompress,
data=data,
)


Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==19.10b0
black==21.5b1
maturin
numpy
pytest>=5.3.0

0 comments on commit f9665a0

Please sign in to comment.