Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a benchmark harness #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ maintenance = { status = "actively-developed" }
rand = { version = "0.8", optional = true }
thiserror = "1.0"

[dev-dependencies]
divan = "0.1"
rand = { version = "0.8" }

[features]
default = []
use-rand = ["rand"]

[[bench]]
name = "kensler"
harness = false
32 changes: 32 additions & 0 deletions benches/kensler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use divan::Bencher;
use hashed_permutation::HashedPermutation;
use rand::seq::SliceRandom;
use rand::thread_rng;
use std::num::NonZeroU32;

const SIZES: [u32; 4] = [100, 1000, 10000, 100000];
const SEED: u32 = 1209;

#[divan::bench(consts = SIZES)]
fn kensler_shuffle<const N: u32>(bencher: Bencher) {
let perm = HashedPermutation::new_with_seed(NonZeroU32::new(N).unwrap(), SEED);

bencher.bench_local(move || {
for i in 0..N {
perm.shuffle(i).unwrap();
}
});
}

#[divan::bench(consts = SIZES)]
fn naive_random_shuffle<const N: u32>(bencher: Bencher) {
let mut v: Vec<u32> = (0..N).collect();
let mut rng = thread_rng();
bencher.bench_local(move || {
v.shuffle(&mut rng);
})
}

fn main() {
divan::main();
}
Loading