Repository: firecracker-microvm/firecracker
File: src/vmm/benches/queue.rs (Rust)

Code before:
        })
    });

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

    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);
                // SAFETY: will never panic.
                unsafe {
                    queue
                        .add_used(&mem, index as u16, len as u32)
                        .unwrap_unchecked()
                };
            }
        })
    });

    c.bench_function("queue_add_used_16", |b| {
        b.iter(|| {
            queue.num_added = Wrapping(0);
            queue.next_used = Wrapping(0);
            for i in 0_u16..16_u16 {
                let index = std::hint::black_box(i);
                let len = std::hint::black_box(i + 1);
                // SAFETY: will never panic.
                unsafe {
                    queue
                        .add_used(&mem, index as u16, len as u32)
                        .unwrap_unchecked()
                };
            }
        })
    });

    c.bench_function("queue_add_used_256", |b| {
        b.iter(|| {
            queue.num_added = Wrapping(0);
            queue.next_used = Wrapping(0);

Review comment (suggestion):
Well, in this case, we can just ignore the return value. It will have the same effect.
```suggestion
                let _ =  queue.add_used(&mem, index as u16, len as u32);
```
same thing everywhere else, really.

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

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

    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(&mem, index as u16, len as u32);
            }
        })
    });

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

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