Skip to content
Merged
Show file tree
Hide file tree
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
53 changes: 53 additions & 0 deletions benches/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,58 @@ fn bench_merge(c: &mut Criterion) {
group.finish();
}

fn bench_is_adjacent(c: &mut Criterion) {
let mut group = c.benchmark_group("netip");

group.bench_function("Ipv4Network::is_adjacent contiguous", |b| {
let n0 = Ipv4Network::parse("192.168.0.0/24").unwrap();
let n1 = Ipv4Network::parse("192.168.1.0/24").unwrap();
b.iter(|| {
core::hint::black_box(core::hint::black_box(&n0).is_adjacent(core::hint::black_box(&n1)));
});
});

group.bench_function("Ipv4Network::is_adjacent non-adjacent", |b| {
let n0 = Ipv4Network::parse("192.168.0.0/24").unwrap();
let n1 = Ipv4Network::parse("192.168.3.0/24").unwrap();
b.iter(|| {
core::hint::black_box(core::hint::black_box(&n0).is_adjacent(core::hint::black_box(&n1)));
});
});

group.bench_function("Ipv4Network::is_adjacent non-contiguous", |b| {
let n0 = Ipv4Network::parse("10.0.0.1/255.255.0.255").unwrap();
let n1 = Ipv4Network::parse("10.1.0.1/255.255.0.255").unwrap();
b.iter(|| {
core::hint::black_box(core::hint::black_box(&n0).is_adjacent(core::hint::black_box(&n1)));
});
});

group.bench_function("Ipv6Network::is_adjacent contiguous", |b| {
let n0 = Ipv6Network::parse("2001:db8::/48").unwrap();
let n1 = Ipv6Network::parse("2001:db8:1::/48").unwrap();
b.iter(|| {
core::hint::black_box(core::hint::black_box(&n0).is_adjacent(core::hint::black_box(&n1)));
});
});

group.bench_function("Ipv6Network::is_adjacent non-contiguous", |b| {
let n0 = Ipv6Network::new(
Ipv6Addr::new(0x2001, 0, 0, 0, 0, 0, 0, 1),
Ipv6Addr::new(0xffff, 0xff00, 0, 0, 0, 0, 0, 0xffff),
);
let n1 = Ipv6Network::new(
Ipv6Addr::new(0x2001, 0x0100, 0, 0, 0, 0, 0, 1),
Ipv6Addr::new(0xffff, 0xff00, 0, 0, 0, 0, 0, 0xffff),
);
b.iter(|| {
core::hint::black_box(core::hint::black_box(&n0).is_adjacent(core::hint::black_box(&n1)));
});
});

group.finish();
}

fn bench_is_contiguous(c: &mut Criterion) {
let mut group = c.benchmark_group("netip");

Expand Down Expand Up @@ -355,6 +407,7 @@ criterion_group!(
bench_net_addrs_count,
bench_intersection,
bench_merge,
bench_is_adjacent,
bench_is_contiguous,
bench_aggregate
);
Expand Down
Loading
Loading