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
62 changes: 61 additions & 1 deletion benches/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,72 @@ fn bench_is_contiguous(c: &mut Criterion) {
group.finish();
}

fn bench_aggregate(c: &mut Criterion) {
use netip::{ipv4_aggregate, ipv6_aggregate};

let mut group = c.benchmark_group("netip");

group.throughput(Throughput::Elements(256));
group.bench_function("ipv4_aggregate 256x /24 -> /16", |b| {
let template: Vec<Ipv4Network> = (0..=255u32)
.map(|i| Ipv4Network::from_bits((192 << 24) | (168 << 16) | (i << 8), 0xFFFFFF00))
.collect();
b.iter_batched(
|| template.clone(),
|mut nets| {
core::hint::black_box(ipv4_aggregate(&mut nets));
},
criterion::BatchSize::SmallInput,
);
});

group.throughput(Throughput::Elements(1024));
group.bench_function("ipv4_aggregate 1024 random /20../28", |b| {
let template: Vec<Ipv4Network> = (0..1024u32)
.map(|i| {
let prefix = 20 + (i % 9);
let mask = !0u32 << (32 - prefix);
let addr = ((10u32 << 24) | (i.wrapping_mul(97) % (1 << 24))) & mask;
Ipv4Network::from_bits(addr, mask)
})
.collect();
b.iter_batched(
|| template.clone(),
|mut nets| {
core::hint::black_box(ipv4_aggregate(&mut nets));
},
criterion::BatchSize::SmallInput,
);
});

group.throughput(Throughput::Elements(256));
group.bench_function("ipv6_aggregate 256x /48 -> /40", |b| {
let template: Vec<Ipv6Network> = (0..=255u128)
.map(|i| {
let addr = (0x2001_0db8u128 << 96) | (i << 80);
let mask = !0u128 << 80;
Ipv6Network::from_bits(addr, mask)
})
.collect();
b.iter_batched(
|| template.clone(),
|mut nets| {
core::hint::black_box(ipv6_aggregate(&mut nets));
},
criterion::BatchSize::SmallInput,
);
});

group.finish();
}

criterion_group!(
benches,
bench_net_addrs,
bench_net_addrs_count,
bench_intersection,
bench_merge,
bench_is_contiguous
bench_is_contiguous,
bench_aggregate
);
criterion_main!(benches);
9 changes: 9 additions & 0 deletions proptest-regressions/net.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc e50491feabc1cc012ad90ded43c0c027e9d1f760b75d499117e3f4d85a77344d # shrinks to raw_nets = [(224, 21), (176, 20), (240, 20)]
cc e4a687942e5551a06e7f3e7d26dc48870ab717bc15a2e9f38e180d79818cbd23 # shrinks to raw_nets = [(64, 18), (0, 19), (192, 19), (224, 19)]
cc c76bb98ceea7ca2f6b914806dd279eb6d6d66c922c07b5dcc8e2050864f29efe # shrinks to raw_nets = [(215, 24), (215, 24)]
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ mod net;
pub use macaddr::{MacAddr, MacAddrParseError};
pub use net::{
Contiguous, ContiguousIpNetParseError, IpNetParseError, IpNetwork, Ipv4Network, Ipv4NetworkAddrs, Ipv4NetworkDiff,
Ipv6Network, Ipv6NetworkAddrs, Ipv6NetworkDiff, ipv4_binary_split, ipv6_binary_split,
Ipv6Network, Ipv6NetworkAddrs, Ipv6NetworkDiff, ipv4_aggregate, ipv4_binary_split, ipv6_aggregate,
ipv6_binary_split,
};
Loading
Loading