Debian Codegraph @

benches/common.rs

raw symbols SCIP
1 use std::net::{IpAddr, Ipv4Addr};
2
3 // Generate `count` IPv4 addresses from a deterministic LCG stream.
4 #[must_use]
5 pub fn generate_ipv4(count: u64) -> Vec<IpAddr> {
6 let mut ips = Vec::with_capacity(count as usize);
7 let mut state = 0x4D59_5DF4_D0F3_3173_u64;
8 for _ in 0..count {
9 state = state
10 .wrapping_mul(6_364_136_223_846_793_005)
11 .wrapping_add(1_442_695_040_888_963_407);
12 let ip = Ipv4Addr::new(
13 (state >> 24) as u8,
14 (state >> 32) as u8,
15 (state >> 40) as u8,
16 (state >> 48) as u8,
17 );
18 ips.push(IpAddr::V4(ip));
19 }
20 ips
21 }
22
23 pub fn open_reader(db_file: &str) -> maxminddb::Reader<impl AsRef<[u8]>> {
24 #[cfg(not(feature = "mmap"))]
25 return maxminddb::Reader::open_readfile(db_file).unwrap();
26
27 #[cfg(feature = "mmap")]
28 // SAFETY: The benchmark database file will not be modified during the benchmark.
29 return unsafe { maxminddb::Reader::open_mmap(db_file) }.unwrap();
30 }