Skip to content

Commit

Permalink
Getting the Iai tutorial to work on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mattxwang committed Mar 20, 2023
1 parent 3b08d01 commit 523a1f5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
CARGO_TERM_COLOR: always

jobs:
iai:
name: Bench (iai)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install Valgrind
run: sudo apt install valgrind # sudo is necessary!
- name: Build
run: cargo build --verbose
- name: Bench
run: cargo bench --verbose
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ petgraph = "0.6.2"
rsgm = { git = "https://github.com/pmall-neu/rsgm" }
rand_chacha = "0.3.1"

[dev-dependencies]
iai = "0.1"

[lib]
name = "rsdd"
Expand Down Expand Up @@ -59,3 +61,7 @@ path = "bin/bayesian_network_compiler.rs"
[[bin]]
name = "semantic_hash_experiment"
path = "bin/semantic_hash_experiment.rs"

[[bench]]
name = "iai"
harness = false
19 changes: 19 additions & 0 deletions benches/iai.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use iai::black_box;

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

fn iai_benchmark_short() -> u64 {
fibonacci(black_box(10))
}

fn iai_benchmark_long() -> u64 {
fibonacci(black_box(30))
}

iai::main!(iai_benchmark_short, iai_benchmark_long);

0 comments on commit 523a1f5

Please sign in to comment.