Skip to content

Commit

Permalink
Fix tpt measurement in benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
aswaving committed Nov 27, 2024
1 parent 519fb69 commit f909f62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions benches/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fn decode_buffer(c: &mut Criterion) {
let mut group = c.benchmark_group("decode");

group
.throughput(Throughput::Bytes(length as u64))
.bench_function("decode 32k", move |b| {
buf.clear();
b.iter(|| yenc::decode_buffer(&encoded).unwrap())
})
.throughput(Throughput::Bytes(length as u64));
});

group.finish();
}
Expand All @@ -32,15 +32,15 @@ fn decode_stream(c: &mut Criterion) {

let mut group = c.benchmark_group("decode_stream");
group
.throughput(Throughput::Bytes(length as u64))
.bench_function("decode_stream 32k", move |b| {
b.iter(|| {
let i = input.clone();
let mut input_r = std::io::Cursor::new(i);
let options = yenc::DecodeOptions::new("/tmp");
options.decode_stream(&mut input_r).unwrap();
});
})
.throughput(Throughput::Bytes(length as u64));
});
}

criterion_group!(benches, decode_buffer, decode_stream);
Expand Down
8 changes: 4 additions & 4 deletions benches/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ fn encode_buffer(c: &mut Criterion) {
let mut output = Vec::with_capacity(32_768 * 102 / 100);
let mut group = c.benchmark_group("encode");
group
.throughput(Throughput::Bytes(length as u64))
.bench_function("encode 32k", move |b| {
b.iter(|| {
output.clear();
yenc::encode_buffer(&buf, 0, 128, &mut output).unwrap()
})
})
.throughput(Throughput::Bytes(length as u64));
});
}
fn encode_stream(c: &mut Criterion) {
let mut group = c.benchmark_group("encode_stream");
group
.throughput(Throughput::Bytes(32_768))
.bench_function("encode_stream 32k", |b| {
b.iter(|| {
let buf = (0..32_768).map(|c| (c % 256) as u8).collect::<Vec<u8>>();
Expand All @@ -31,8 +32,7 @@ fn encode_stream(c: &mut Criterion) {
.encode_stream(&mut input_r, &mut output_r, length as u64, "test")
.unwrap();
})
})
.throughput(Throughput::Bytes(32_768));
});
}

criterion_group!(benches, encode_buffer, encode_stream);
Expand Down

0 comments on commit f909f62

Please sign in to comment.