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

Add parameter benchmarking to read_bytes #32

Merged
merged 1 commit into from
Jan 13, 2024
Merged
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
43 changes: 24 additions & 19 deletions compare/benches/bench_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,26 +399,31 @@ fn real_world2(c: &mut Criterion) {
fn read_bytes(c: &mut Criterion) {
let mut group = c.benchmark_group("read_bytes");

group.bench_function("aligned", |b| {
b.iter(|| {
let mut buf = [0u8; 7];
let mut bitter = LittleEndianReader::new(&DATA[..]);
for _ in 0..ITER {
black_box(bitter.read_bytes(&mut buf));
}
})
});
for i in &[5, 20, 80, 240, 960] {
let iterations = DATA.len() / *i;
group.throughput(Throughput::Bytes((iterations * *i) as u64));

group.bench_function("unaligned", |b| {
b.iter(|| {
let mut buf = [0u8; 7];
let mut bitter = LittleEndianReader::new(&DATA[..]);
bitter.read_bit();
for _ in 0..ITER {
black_box(bitter.read_bytes(&mut buf));
}
})
});
group.bench_with_input(BenchmarkId::new("aligned", i), &i, |b, param| {
let mut buf = vec![0u8; **param];
b.iter(|| {
let mut bitter = LittleEndianReader::new(&DATA[..]);
for _ in 0..iterations {
assert!(black_box(bitter.read_bytes(&mut buf)));
}
})
});

group.bench_with_input(BenchmarkId::new("unaligned", i), &i, |b, param| {
let mut buf = vec![0u8; **param];
b.iter(|| {
let mut bitter = LittleEndianReader::new(&DATA[..]);
bitter.read_bit();
for _ in 0..iterations {
assert!(black_box(bitter.read_bytes(&mut buf)));
}
})
});
}

group.finish();
}
Expand Down