-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e670d00
commit 2dc4c18
Showing
7 changed files
with
196 additions
and
0 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,37 @@ | ||
name: Criterion.rs with Benchmark Action | ||
on: [push] | ||
|
||
permissions: | ||
contents: write | ||
deployments: write | ||
|
||
jobs: | ||
benchmark: | ||
name: Run Criterion.rs benchmark example | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: Install Rust Toolchain | ||
id: toolchain | ||
uses: dtolnay/rust-toolchain@v1 | ||
with: | ||
toolchain: "nightly" | ||
- name: Prepare for benchmark | ||
run: cargo run --example benchmark_integers | ||
- name: Run benchmark | ||
run: cargo bench -- --output-format bencher | tee output.txt | ||
- name: Store benchmark result - separate results repo | ||
uses: benchmark-action/github-action-benchmark@v1 | ||
with: | ||
name: Criterion.rs Benchmark | ||
tool: "cargo" | ||
output-file-path: output.txt | ||
github-token: ${{ secrets.BENCHMARK_ACTION_BOT_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: "@TheVeryDarkness" | ||
gh-repository: "github.com/TheVeryDarkness/iof-benchmark-results" |
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 @@ | ||
integers.txt |
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,41 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use iof::{unwrap, InputStream, ReadInto, ReadOneInto}; | ||
use std::{fs::read_to_string, io::Cursor}; | ||
|
||
const COUNT: usize = 0x10000 * 4; | ||
|
||
fn many_integers(c: &mut Criterion) { | ||
let s = unwrap!(read_to_string("benches/integers.txt")); | ||
c.bench_function("read_all", |_| { | ||
let mut reader = InputStream::new(Cursor::new(s.as_str())); | ||
let results: Vec<i32> = reader.read_all(); | ||
assert_eq!(results.len(), COUNT); | ||
}) | ||
.bench_function("read_n", |_| { | ||
let mut reader = InputStream::new(Cursor::new(s.as_str())); | ||
let results: Vec<i32> = reader.read_n(COUNT); | ||
assert_eq!(results.len(), COUNT); | ||
}) | ||
.bench_function("read", |_| { | ||
let mut reader = InputStream::new(Cursor::new(s.as_str())); | ||
let results: Vec<i32> = reader.read(); | ||
assert_eq!(results.len(), COUNT); | ||
}) | ||
.bench_function("read while let", |_| { | ||
let mut reader = InputStream::new(Cursor::new(s.as_str())); | ||
let mut results: Vec<i64> = Vec::new(); | ||
while let Ok(a) = reader.try_read_one() { | ||
results.push(a); | ||
} | ||
}) | ||
.bench_function("read for in", |_| { | ||
let mut reader = InputStream::new(Cursor::new(s.as_str())); | ||
let mut results: Vec<i64> = Vec::new(); | ||
for _ in 0..COUNT { | ||
results.push(reader.read()); | ||
} | ||
}); | ||
} | ||
|
||
criterion_group!(benches, many_integers); | ||
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,43 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use iof::{unwrap, InputStream, ReadInto, ReadOneInto}; | ||
use std::{fs::File, io::BufReader}; | ||
|
||
const COUNT: usize = 0x10000 * 4; | ||
|
||
fn create_reader() -> InputStream<BufReader<File>> { | ||
let f = unwrap!(File::open("benches/integers.txt")); | ||
let buf = BufReader::new(f); | ||
InputStream::new(buf) | ||
} | ||
|
||
fn many_integers(c: &mut Criterion) { | ||
c.bench_function("read_all", |_| { | ||
let mut reader = create_reader(); | ||
let _: Vec<i32> = reader.read_all(); | ||
}) | ||
.bench_function("read_n", |_| { | ||
let mut reader = create_reader(); | ||
let _: Vec<i32> = reader.read_n(COUNT); | ||
}) | ||
.bench_function("read", |_| { | ||
let mut reader = create_reader(); | ||
let _: Vec<i32> = reader.read(); | ||
}) | ||
.bench_function("read while let", |_| { | ||
let mut reader = create_reader(); | ||
let mut results: Vec<i64> = Vec::new(); | ||
while let Ok(a) = reader.try_read_one() { | ||
results.push(a); | ||
} | ||
}) | ||
.bench_function("read for in", |_| { | ||
let mut reader = create_reader(); | ||
let mut results: Vec<i64> = Vec::new(); | ||
for _ in 0..COUNT { | ||
results.push(reader.read()); | ||
} | ||
}); | ||
} | ||
|
||
criterion_group!(benches, many_integers); | ||
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,38 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use iof::{sep_by, show, unwrap}; | ||
|
||
fn many_integers(c: &mut Criterion) { | ||
let s = unwrap!(std::fs::read_to_string("benches/integers.txt")); | ||
c.bench_function("default_separator", |_| { | ||
let mut buf = Vec::new(); | ||
let integers = [ | ||
-0x10000i64..0x10000i64, | ||
-0x80000000..-0x7fff0000, | ||
0x70000000..0x70010000, | ||
]; | ||
show!(sep_by!(integers, "\n", " ") => buf); | ||
assert_eq!(buf, s.as_bytes()); | ||
}) | ||
.bench_function("longer_separator", |_| { | ||
let mut buf = Vec::new(); | ||
let integers = [ | ||
-0x10000i64..0x10000i64, | ||
-0x80000000..-0x7fff0000, | ||
0x70000000..0x70010000, | ||
]; | ||
show!(sep_by!(integers, "\n\n", " :: ") => buf); | ||
assert_eq!(buf, s.as_bytes()); | ||
}) | ||
.bench_function("char_separator", |_| { | ||
let mut buf = Vec::new(); | ||
let integers = [ | ||
-0x10000i64..0x10000i64, | ||
-0x80000000..-0x7fff0000, | ||
0x70000000..0x70010000, | ||
]; | ||
show!(sep_by!(integers, '\n', ' ') => buf); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, many_integers); | ||
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,23 @@ | ||
//! Run `cargo run --example benchmark_integers` to prepare data for the benchmark. | ||
use iof::{sep_by, show, unwrap}; | ||
use std::{fs::File, path::PathBuf}; | ||
|
||
fn main() { | ||
let integers = [ | ||
-0x10000i64..0x10000i64, | ||
-0x80000000..-0x7fff0000, | ||
0x70000000..0x70010000, | ||
]; | ||
|
||
let manifest_dir = env!("CARGO_MANIFEST_DIR"); | ||
|
||
let mut results = PathBuf::from(manifest_dir); | ||
results.push("benches"); | ||
results.push("integers.txt"); | ||
|
||
let mut f = unwrap!(File::create(results)); | ||
|
||
// Write integers to file | ||
show!(sep_by!(integers, "\n", " ") => f); | ||
} |