Skip to content

Commit a764ece

Browse files
committed
👷 Run criterion benchmarks on CI with cargo-codspeed
Use codspeed-criterion-compat crate inplace of criterion, and setup CI job to run the Rust benchmarks!
1 parent 2da7d6d commit a764ece

File tree

3 files changed

+180
-38
lines changed

3 files changed

+180
-38
lines changed

.github/workflows/benchmarks.yml

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Run performance benchmarks
22
#
3-
# Continuous benchmarking using pytest-codspeed. Measures the execution speed
4-
# of tests marked with @pytest.mark.benchmark decorator.
3+
# Continuous benchmarking with CodSpeed. Measures the execution speed of Rust benchmarks
4+
# via cargo-codspeed, and Python tests marked with @pytest.mark.benchmark decorator.
55

66
name: Benchmarks
77

@@ -16,10 +16,45 @@ on:
1616
# performance analysis in order to generate initial data.
1717
workflow_dispatch:
1818

19+
env:
20+
CARGO_TERM_COLOR: always
21+
1922
permissions: {}
2023

2124
jobs:
22-
benchmarks:
25+
rust-benchmarks:
26+
name: "Run Rust benchmarks"
27+
runs-on: ubuntu-24.04
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
31+
with:
32+
persist-credentials: false
33+
34+
- name: Download sample GeoTIFF
35+
run: |
36+
curl --create-dir --remote-name --output-dir benches https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/37/M/BV/2024/10/S2A_37MBV_20241029_0_L2A/TCI.tif
37+
ls -lh benches/
38+
39+
- name: Setup rust toolchain, cache and cargo-codspeed binary
40+
uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2
41+
with:
42+
channel: 1.85.0 # msrv
43+
cache: false
44+
cache-target: release
45+
bins: cargo-codspeed
46+
47+
- name: Build the benchmark target(s)
48+
run: cargo codspeed build
49+
50+
- name: Run the benchmarks
51+
uses: CodSpeedHQ/action@6a8e2b874c338bf81cc5e8be715ada75908d3871 # v4.3.4
52+
with:
53+
mode: instrumentation
54+
run: cargo codspeed run
55+
56+
python-benchmarks:
57+
name: "Run Python benchmarks"
2358
runs-on: ubuntu-24.04
2459
defaults:
2560
run:
@@ -28,7 +63,7 @@ jobs:
2863
steps:
2964
# Checkout current git repository
3065
- name: Checkout
31-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
66+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3267
with:
3368
persist-credentials: false
3469

@@ -55,7 +90,7 @@ jobs:
5590
5691
# Run the benchmark tests
5792
- name: Run benchmarks
58-
uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d # v3.5.0
93+
uses: CodSpeedHQ/action@6a8e2b874c338bf81cc5e8be715ada75908d3871 # v4.3.4
5994
with:
60-
run: |
61-
python -m pytest --verbose --codspeed
95+
mode: instrumentation
96+
run: python -m pytest --verbose --codspeed

Cargo.lock

Lines changed: 137 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tokio = { version = "1.36.0", features = ["rt-multi-thread"] }
3838
url = { version = "2.5.7", optional = true }
3939

4040
[dev-dependencies]
41-
criterion = "0.7.0"
41+
criterion = { package = "codspeed-criterion-compat", version = "4.1.0" }
4242
gdal = { version = "0.18.0", features = ["array"] }
4343
# comment out gdal-src and gdal-sys if libgdal-dev installed
4444
gdal-src = { version = "0.2.1", features = ["driver_gtiff", "nobuild"] }

0 commit comments

Comments
 (0)