Skip to content

Commit

Permalink
feat: init benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyphack committed Jun 6, 2024
1 parent ca5451d commit 46ae14a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: codspeed-benchmarks

on:
push:
branches:
- "main" # or "master"
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

- name: Run the benchmarks
uses: CodSpeedHQ/action@v2
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ log = { version = "0.4.17" }
serde = { version = "1.0.152", features = ["derive"] }
miette = { version = "7.2.0", features = ["fancy"] }
insta = { version = "1.38.0", features = ["filters", "glob"] }
codspeed-criterion-compat = "2.6.0"
thiserror = "1.0.48"
criterion = "0.5.1"

[profile.dev.package.insta]
opt-level = 3
Expand Down
6 changes: 6 additions & 0 deletions parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ thiserror = "1.0.40"
is-macro = "0.3.5"

[dev-dependencies]
codspeed-criterion-compat = "2.6.0"
criterion.workspace = true
insta.workspace = true

[[bench]]
name = "parser_benchmark"
harness = false
16 changes: 16 additions & 0 deletions parser/benches/parser_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion};

fn fibonacci(n: u64) -> u64 {
match n {
0 => 1,
1 => 1,
n => fibonacci(n - 1) + fibonacci(n - 2),
}
}

pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20))));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

0 comments on commit 46ae14a

Please sign in to comment.