-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci/bench): add bencher configuration (#307)
- Loading branch information
Showing
9 changed files
with
178 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Bencher | ||
|
||
on: | ||
push: | ||
branches: main | ||
pull_request: | ||
types: [opened, reopened, edited, synchronize] | ||
|
||
jobs: | ||
benchmark_base: | ||
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: bencherdev/bencher@main | ||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
- name: Base branch benchmarks | ||
run: | | ||
bencher run \ | ||
--branch main \ | ||
--testbed ubuntu-latest \ | ||
--err | ||
env: | ||
BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }} | ||
BENCHER_CMD: cargo bench --all-features | ||
BENCHER_PROJECT: socketioxide | ||
RUSTFLAGS: --cfg=socketioxide_test | ||
|
||
benchmark_pr: | ||
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository | ||
permissions: | ||
pull-requests: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
- uses: bencherdev/bencher@main | ||
- name: PR benchmarks | ||
run: | | ||
bencher run \ | ||
--branch '${{ github.head_ref }}' \ | ||
--branch-start-point '${{ github.base_ref }}' \ | ||
--branch-start-point-hash '${{ github.event.pull_request.base.sha }}' \ | ||
--testbed ubuntu-latest \ | ||
--err \ | ||
--github-actions '${{ secrets.GITHUB_TOKEN }}' | ||
env: | ||
BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }} | ||
BENCHER_CMD: cargo bench --all-features | ||
BENCHER_PROJECT: socketioxide | ||
RUSTFLAGS: --cfg=socketioxide_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; | ||
use rand::Rng; | ||
use socketioxide::extensions::Extensions; | ||
|
||
fn bench_extensions(c: &mut Criterion) { | ||
let i = black_box(5i32); | ||
let mut group = c.benchmark_group("extensions"); | ||
group.bench_function("concurrent_inserts", |b| { | ||
let ext = Extensions::new(); | ||
b.iter(|| { | ||
ext.insert(i); | ||
}); | ||
}); | ||
group.bench_function("concurrent_get", |b| { | ||
let ext = Extensions::new(); | ||
ext.insert(i); | ||
b.iter(|| { | ||
ext.get::<i32>(); | ||
}) | ||
}); | ||
group.bench_function("concurrent_get_inserts", |b| { | ||
let ext = Extensions::new(); | ||
b.iter_batched( | ||
|| rand::thread_rng().gen_range(0..3), | ||
|i| { | ||
if i == 0 { | ||
ext.insert(i); | ||
} else { | ||
ext.get::<i32>(); | ||
} | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_extensions); | ||
criterion_main!(benches); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.