Skip to content

Commit

Permalink
rand benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
naftulikay committed Nov 4, 2023
1 parent 0bdfaa4 commit 193731b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ members = [
"example_parsing",
]

[profile.bench]
debug = true

[workspace.dependencies]
anyhow = "1"
clap = { version = "4", features = ["derive"] }
Expand Down
4 changes: 4 additions & 0 deletions example_crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ publish = false
name = "keygen"
harness = false

[[bench]]
name = "rand"
harness = false

[[bench]]
name = "sign"
harness = false
Expand Down
39 changes: 39 additions & 0 deletions example_crypto/benches/rand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use criterion::{criterion_group, criterion_main, Criterion};
use rand::{thread_rng, RngCore};

fn bench_rand_thread_rng(c: &mut Criterion) {
// stack tests
c.bench_function("rand::thread_rng::stack_32", |b| {
b.iter(|| {
let mut s = [0; 32];
thread_rng().fill_bytes(&mut s);
})
});
c.bench_function("rand::thread_rng::stack_64", |b| {
b.iter(|| {
let mut s = [0; 64];
thread_rng().fill_bytes(&mut s);
})
});
// vec tests
c.bench_function("rand::thread_rng::alloc_32", |b| {
b.iter(|| {
let mut v = vec![0; 32];
thread_rng().fill_bytes(&mut v.as_mut_slice());
})
});
c.bench_function("rand::thread_rng::alloc_64", |b| {
b.iter(|| {
let mut v = vec![0; 64];
thread_rng().fill_bytes(&mut v.as_mut_slice());
})
});
}

criterion_group! {
name = rand;
config = Criterion::default();
targets = bench_rand_thread_rng
}

criterion_main!(rand);

0 comments on commit 193731b

Please sign in to comment.