Skip to content

Commit

Permalink
chore: update too fast benches
Browse files Browse the repository at this point in the history
Some benchmarks are very small and fast and this causes them to
be unstable. We can still keep an eye on the performance with
longer benches. Also increased number of runs and threshold.
This should be fine as all tests still run in nanoseconds.

Signed-off-by: Egor Lazarchuk <[email protected]>
  • Loading branch information
ShadowCurse committed Sep 18, 2024
1 parent a4b3d93 commit 5d762a8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/vmm/benches/block_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use vmm::devices::virtio::test_utils::VirtQueue;
use vmm::test_utils::single_region_mem;

pub fn block_request_benchmark(c: &mut Criterion) {
let mem = single_region_mem(2 * 65562);
let mem = single_region_mem(65562);
let virt_queue = VirtQueue::new(GuestAddress(0), &mem, 16);

// We don't really care about what request is. We just
Expand All @@ -36,7 +36,7 @@ pub fn block_request_benchmark(c: &mut Criterion) {

criterion_group! {
name = block_request_benches;
config = Criterion::default().sample_size(200).noise_threshold(0.05);
config = Criterion::default().sample_size(1000).noise_threshold(0.05);
targets = block_request_benchmark
}

Expand Down
72 changes: 1 addition & 71 deletions src/vmm/benches/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,6 @@ pub fn queue_benchmark(c: &mut Criterion) {
let rxq = VirtQueue::new(GuestAddress(0), &mem, 256);
let mut queue = rxq.create_queue();

set_dtable_one_chain(&rxq, 1);
queue.next_avail = Wrapping(0);
let desc = queue.pop().unwrap();
c.bench_function("next_descriptor_1", |b| {
b.iter(|| {
let mut head = Some(desc);
while let Some(d) = head {
head = std::hint::black_box(d.next_descriptor());
}
})
});

set_dtable_one_chain(&rxq, 2);
queue.next_avail = Wrapping(0);
let desc = queue.pop().unwrap();
c.bench_function("next_descriptor_2", |b| {
b.iter(|| {
let mut head = Some(desc);
while let Some(d) = head {
head = std::hint::black_box(d.next_descriptor());
}
})
});

set_dtable_one_chain(&rxq, 4);
queue.next_avail = Wrapping(0);
let desc = queue.pop().unwrap();
c.bench_function("next_descriptor_4", |b| {
b.iter(|| {
let mut head = Some(desc);
while let Some(d) = head {
head = std::hint::black_box(d.next_descriptor());
}
})
});

set_dtable_one_chain(&rxq, 16);
queue.next_avail = Wrapping(0);
let desc = queue.pop().unwrap();
Expand All @@ -107,28 +71,6 @@ pub fn queue_benchmark(c: &mut Criterion) {
})
});

// Queue pop

set_dtable_many_chains(&rxq, 1);
c.bench_function("queue_pop_1", |b| {
b.iter(|| {
queue.next_avail = Wrapping(0);
while let Some(desc) = queue.pop() {
std::hint::black_box(desc);
}
})
});

set_dtable_many_chains(&rxq, 4);
c.bench_function("queue_pop_4", |b| {
b.iter(|| {
queue.next_avail = Wrapping(0);
while let Some(desc) = queue.pop() {
std::hint::black_box(desc);
}
})
});

set_dtable_many_chains(&rxq, 16);
c.bench_function("queue_pop_16", |b| {
b.iter(|| {
Expand All @@ -139,18 +81,6 @@ pub fn queue_benchmark(c: &mut Criterion) {
})
});

c.bench_function("queue_add_used_1", |b| {
b.iter(|| {
queue.num_added = Wrapping(0);
queue.next_used = Wrapping(0);
for i in 0_u16..1_u16 {
let index = std::hint::black_box(i);
let len = std::hint::black_box(i + 1);
_ = queue.add_used(index as u16, len as u32);
}
})
});

c.bench_function("queue_add_used_16", |b| {
b.iter(|| {
queue.num_added = Wrapping(0);
Expand Down Expand Up @@ -178,7 +108,7 @@ pub fn queue_benchmark(c: &mut Criterion) {

criterion_group! {
name = queue_benches;
config = Criterion::default().sample_size(200).noise_threshold(0.05);
config = Criterion::default().sample_size(1000).noise_threshold(0.15);
targets = queue_benchmark
}

Expand Down

0 comments on commit 5d762a8

Please sign in to comment.