summaryrefslogtreecommitdiffstats
path: root/vendor/ruzstd/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/ruzstd/benches
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ruzstd/benches')
-rw-r--r--vendor/ruzstd/benches/reversedbitreader_bench.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/ruzstd/benches/reversedbitreader_bench.rs b/vendor/ruzstd/benches/reversedbitreader_bench.rs
new file mode 100644
index 000000000..89b01e1f5
--- /dev/null
+++ b/vendor/ruzstd/benches/reversedbitreader_bench.rs
@@ -0,0 +1,38 @@
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use rand::Rng;
+use ruzstd::decoding::bit_reader_reverse::BitReaderReversed;
+
+fn fibonacci(br: &mut BitReaderReversed, accesses: &[u8]) -> u64 {
+ let mut sum = 0;
+ for x in accesses {
+ sum += br.get_bits(*x).unwrap() as u64;
+ }
+ let _ = black_box(br);
+ sum
+}
+
+fn criterion_benchmark(c: &mut Criterion) {
+ let mut rng = rand::thread_rng();
+ let mut rand_vec = vec![];
+ for _ in 0..100000 {
+ rand_vec.push(rng.gen());
+ }
+
+ let mut access_vec = vec![];
+ let mut br = BitReaderReversed::new(&rand_vec);
+ while br.bits_remaining() > 0 {
+ let x = rng.gen_range(1..20);
+ br.get_bits(x).unwrap();
+ access_vec.push(x);
+ }
+
+ c.bench_function("fib 20", |b| {
+ b.iter(|| {
+ br.reset(&rand_vec);
+ fibonacci(&mut br, &access_vec)
+ })
+ });
+}
+
+criterion_group!(benches, criterion_benchmark);
+criterion_main!(benches);