mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-17 09:18:51 +00:00
Merge pull request #113 from achanda/bench-netmask
Add a benchmark for parsing IPv4 netmask
This commit is contained in:
@ -2,8 +2,8 @@ use criterion::{criterion_group, criterion_main, Criterion};
|
|||||||
use ipnetwork::{Ipv4Network, Ipv6Network};
|
use ipnetwork::{Ipv4Network, Ipv6Network};
|
||||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||||
|
|
||||||
fn parse_ipv4_benchmark(c: &mut Criterion) {
|
fn parse_ipv4_prefix_benchmark(c: &mut Criterion) {
|
||||||
c.bench_function("parse ipv4", |b| {
|
c.bench_function("parse ipv4 prefix", |b| {
|
||||||
b.iter(|| "127.1.0.0/24".parse::<Ipv4Network>().unwrap())
|
b.iter(|| "127.1.0.0/24".parse::<Ipv4Network>().unwrap())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -14,6 +14,12 @@ fn parse_ipv6_benchmark(c: &mut Criterion) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_ipv4_netmask_benchmark(c: &mut Criterion) {
|
||||||
|
c.bench_function("parse ipv4 netmask", |b| {
|
||||||
|
b.iter(|| "127.1.0.0/255.255.255.0".parse::<Ipv4Network>().unwrap())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn contains_ipv4_benchmark(c: &mut Criterion) {
|
fn contains_ipv4_benchmark(c: &mut Criterion) {
|
||||||
c.bench_function("contains ipv4", |b| {
|
c.bench_function("contains ipv4", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
@ -34,8 +40,9 @@ fn contains_ipv6_benchmark(c: &mut Criterion) {
|
|||||||
|
|
||||||
criterion_group!(
|
criterion_group!(
|
||||||
benches,
|
benches,
|
||||||
parse_ipv4_benchmark,
|
parse_ipv4_prefix_benchmark,
|
||||||
parse_ipv6_benchmark,
|
parse_ipv6_benchmark,
|
||||||
|
parse_ipv4_netmask_benchmark,
|
||||||
contains_ipv4_benchmark,
|
contains_ipv4_benchmark,
|
||||||
contains_ipv6_benchmark
|
contains_ipv6_benchmark
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user