summaryrefslogtreecommitdiffstats
path: root/third_party/rust/neqo-transport/benches/range_tracker.rs
blob: c2f78f48748e907460f0fd0779bf1f40ce472964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use criterion::{criterion_group, criterion_main, Criterion}; // black_box
use neqo_transport::send_stream::RangeTracker;

const CHUNK: u64 = 1000;
const END: u64 = 100_000;
fn build_coalesce(len: u64) -> RangeTracker {
    let mut used = RangeTracker::default();
    used.mark_acked(0, CHUNK as usize);
    used.mark_sent(CHUNK, END as usize);
    // leave a gap or it will coalesce here
    for i in 2..=len {
        // These do not get immediately coalesced when marking since they're not at the end or start
        used.mark_acked(i * CHUNK, CHUNK as usize);
    }
    used
}

fn coalesce(c: &mut Criterion, count: u64) {
    c.bench_function(
        &format!("coalesce_acked_from_zero {count}+1 entries"),
        |b| {
            b.iter_batched_ref(
                || build_coalesce(count),
                |used| {
                    used.mark_acked(CHUNK, CHUNK as usize);
                    let tail = (count + 1) * CHUNK;
                    used.mark_sent(tail, CHUNK as usize);
                    used.mark_acked(tail, CHUNK as usize);
                },
                criterion::BatchSize::SmallInput,
            )
        },
    );
}

fn benchmark_coalesce(c: &mut Criterion) {
    coalesce(c, 1);
    coalesce(c, 3);
    coalesce(c, 10);
    coalesce(c, 1000);
}

criterion_group!(benches, benchmark_coalesce);
criterion_main!(benches);