Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use codspeed to report benchmarks #223

Merged
merged 5 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: codspeed-benchmarks

on:
push:
branches:
- "main"
pull_request:
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup rust toolchain, cache and cargo-codspeed binary
uses: moonrepo/setup-rust@v0
with:
channel: stable
cache-target: release
bins: cargo-codspeed

- name: Build the benchmark target(s)
run: cargo codspeed build -p biscuit-auth

- name: Run the benchmarks
uses: CodSpeedHQ/action@v2
with:
run: cargo codspeed run -p biscuit-auth
token: ${{ secrets.CODSPEED_TOKEN }}
1 change: 1 addition & 0 deletions biscuit-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ colored-diff = "0.2.3"
prost-build = "0.10"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.67"
codspeed-bencher-compat = "2.6.0"

#[build-dependencies]
#prost-build = "0.10"
Expand Down
88 changes: 71 additions & 17 deletions biscuit-auth/benches/token.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[macro_use]
extern crate bencher;

extern crate biscuit_auth as biscuit;

use bencher::Bencher;
use std::time::Duration;

use biscuit::{
builder::*, builder_ext::BuilderExt, datalog::SymbolTable, Biscuit, KeyPair, UnverifiedBiscuit,
builder::*, builder_ext::BuilderExt, datalog::SymbolTable, AuthorizerLimits, Biscuit, KeyPair,
UnverifiedBiscuit,
};
use codspeed_bencher_compat::{benchmark_group, benchmark_main, Bencher};
use rand::rngs::OsRng;

fn create_block_1(b: &mut Bencher) {
Expand Down Expand Up @@ -245,16 +245,25 @@ fn verify_block_2(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();

verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();
b.bytes = data.len() as u64;
b.iter(|| {
let token = Biscuit::from(&data, &root.public()).unwrap();
let mut verifier = token.authorizer().unwrap();
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();
});
}

Expand Down Expand Up @@ -314,7 +323,12 @@ fn verify_block_5(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();

b.bytes = data.len() as u64;
b.iter(|| {
Expand All @@ -323,7 +337,12 @@ fn verify_block_5(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();
});
}

Expand Down Expand Up @@ -356,7 +375,12 @@ fn check_signature_2(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();

b.bytes = data.len() as u64;
b.iter(|| {
Expand Down Expand Up @@ -419,7 +443,12 @@ fn check_signature_5(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();

b.bytes = data.len() as u64;
b.iter(|| {
Expand Down Expand Up @@ -456,7 +485,12 @@ fn checks_block_2(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();

let token = Biscuit::from(&data, &root.public()).unwrap();
b.bytes = data.len() as u64;
Expand All @@ -465,7 +499,12 @@ fn checks_block_2(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();
});
}

Expand Down Expand Up @@ -498,7 +537,12 @@ fn checks_block_create_verifier2(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();

let token = Biscuit::from(&data, &root.public()).unwrap();
b.bytes = data.len() as u64;
Expand Down Expand Up @@ -536,15 +580,25 @@ fn checks_block_verify_only2(b: &mut Bencher) {
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();

let token = Biscuit::from(&data, &root.public()).unwrap();
b.iter(|| {
let mut verifier = token.authorizer().unwrap();
verifier.add_fact("resource(\"file1\")");
verifier.add_fact("operation(\"read\")");
verifier.allow();
verifier.authorize().unwrap();
verifier
.authorize_with_limits(AuthorizerLimits {
max_time: Duration::from_secs(10),
..Default::default()
})
.unwrap();
});
}

Expand Down
Loading