-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from morenol/master
Allow '/' in test name (rust)
- Loading branch information
Showing
7 changed files
with
146 additions
and
1 deletion.
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,29 @@ | ||
name: Criterion.rs Example | ||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
benchmark: | ||
name: Run Criterion.rs benchmark example | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: rustup toolchain update | ||
- name: Run benchmark | ||
run: cd examples/criterion-rs && cargo bench -- --output-format bencher | tee output.txt | ||
- name: Store benchmark result | ||
uses: rhysd/github-action-benchmark@v1 | ||
with: | ||
name: Rust Benchmark | ||
tool: 'cargo' | ||
output-file-path: examples/criterion-rs/output.txt | ||
# Use personal access token instead of GITHUB_TOKEN due to https://github.community/t5/GitHub-Actions/Github-action-not-triggering-gh-pages-upon-push/td-p/26869/highlight/false | ||
github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} | ||
auto-push: true | ||
# Show alert with commit comment on detecting possible performance regression | ||
alert-threshold: '200%' | ||
comment-on-alert: true | ||
fail-on-alert: true | ||
alert-comment-cc-users: '@rhysd' |
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,17 @@ | ||
[package] | ||
name = "criterion_example" | ||
version = "0.1.0" | ||
authors = ["rhysd <https://rhysd.github.io>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
criterion = "*" | ||
|
||
[lib] | ||
bench = false | ||
|
||
[[bench]] | ||
name = "bench" | ||
harness = false |
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,37 @@ | ||
# Rust Criterion example for benchmarking with `cargo bench` | ||
|
||
- [Workflow for this example](../../.github/workflows/criterion-rs.yml) | ||
- [Benchmark results on GitHub pages](https://rhysd.github.io/github-action-benchmark/dev/bench/) | ||
|
||
This directory shows how to use [`github-action-benchmark`](https://github.com/rhysd/github-action-benchmark) | ||
with [`criterion`](https://github.com/bheisler/criterion.rs). | ||
|
||
## Run benchmarks | ||
|
||
Official documentation for usage of `cargo bench` with Criterion: | ||
|
||
https://github.com/bheisler/criterion.rs | ||
|
||
e.g. | ||
|
||
```yaml | ||
- name: Run benchmark | ||
run: cargo bench -- --output-format bencher | tee output.txt | ||
``` | ||
Note that you should run the benchmarks using the bencher output format. | ||
## Process benchmark results | ||
Store the benchmark results with step using the action. Please set `cargo` to `tool` input. | ||
|
||
```yaml | ||
- name: Store benchmark result | ||
uses: rhysd/github-action-benchmark@v1 | ||
with: | ||
tool: 'cargo' | ||
output-file-path: output.txt | ||
``` | ||
|
||
Please read ['How to use' section](https://github.com/rhysd/github-action-benchmark#how-to-use) for common usage. |
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,35 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
use criterion::{black_box, Criterion, BenchmarkId}; | ||
use criterion_example::{fib, fast_fib}; | ||
|
||
fn bench_fib_10(c: &mut Criterion) { | ||
c.bench_function("BenchFib10", move |b| { | ||
b.iter(|| { | ||
let _ = fib(black_box(10)); | ||
}); | ||
}); | ||
} | ||
|
||
fn bench_fib_20(c: &mut Criterion) { | ||
c.bench_function("BenchFib20", move |b| { | ||
b.iter(|| { | ||
let _ = fib(20); | ||
}); | ||
}); | ||
} | ||
|
||
fn bench_fibs(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Fibonacci"); | ||
for i in [20, 21].iter() { | ||
group.bench_with_input(BenchmarkId::new("Recursive", i), i, | ||
|b, i| b.iter(|| fib(*i))); | ||
group.bench_with_input(BenchmarkId::new("Iterative", i), i, | ||
|b, i| b.iter(|| fast_fib(*i))); | ||
} | ||
group.finish(); | ||
} | ||
|
||
|
||
criterion_group!(benches, bench_fib_10, bench_fib_20, bench_fibs); | ||
criterion_main!(benches); |
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,25 @@ | ||
pub fn fib(u: u32) -> u32 { | ||
if u <= 1 { | ||
1 | ||
} else { | ||
fib(u - 2) + fib(u - 1) | ||
} | ||
} | ||
|
||
pub fn fast_fib(n: u32) -> u32 { | ||
let mut a = 0; | ||
let mut b = 1; | ||
|
||
match n { | ||
0 => b, | ||
_ => { | ||
for _ in 0..n { | ||
let c = a + b; | ||
a = b; | ||
b = c; | ||
} | ||
b | ||
} | ||
} | ||
} | ||
|
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