Browse Source

utils: add permutation benchmark

Lennart Braun 2 years ago
parent
commit
beedade51c
2 changed files with 27 additions and 0 deletions
  1. 7 0
      utils/Cargo.toml
  2. 20 0
      utils/benches/permutation.rs

+ 7 - 0
utils/Cargo.toml

@@ -15,3 +15,10 @@ num-bigint = "0.4.3"
 num-traits = "0.2.15"
 rand = "0.8.5"
 rand_chacha = "0.3.1"
+
+[dev-dependencies]
+criterion = "0.4.0"
+
+[[bench]]
+name = "permutation"
+harness = false

+ 20 - 0
utils/benches/permutation.rs

@@ -0,0 +1,20 @@
+use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
+use utils::permutation::{FisherYatesPermutation, Permutation};
+
+const LOG_DOMAIN_SIZES: [u32; 4] = [8, 12, 16, 20];
+
+pub fn bench_permutation(c: &mut Criterion) {
+    for log_domain_size in LOG_DOMAIN_SIZES {
+        c.bench_with_input(
+            BenchmarkId::new("FisherYates", log_domain_size),
+            &log_domain_size,
+            |b, &log_domain_size| {
+                let key = FisherYatesPermutation::sample(log_domain_size);
+                b.iter(|| black_box(FisherYatesPermutation::from_key(key)))
+            },
+        );
+    }
+}
+
+criterion_group!(benches, bench_permutation);
+criterion_main!(benches);