#![feature(test)] extern crate test; use test::Bencher; use std::fs::File; use std::io::{BufRead, BufReader}; use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; use ip_network_table_deps_treebitmap::IpLookupTable; use iptrie::{IpPrefix, Ipv4Prefix, Ipv6Prefix, Ipv6Prefix120, LCTrieSet, RTrieSet}; fn read_ip() -> impl Iterator { let file = File::open("benches/bgpas.lpm").expect("can’t open LPM file"); BufReader::new(file) .lines() .map_while(Result::ok) .filter_map(|l| { let prefix = l.split(' ').next().expect("bad formatted file"); prefix.parse::

().ok() }).take(100_000) } #[bench] fn nop_ipv4prefix_trie(bencher: &mut Bencher) { let mut result = Vec::with_capacity(1_000_000); bencher.iter(|| result.extend(read_ip::())); println!("{}", result.len()); } #[bench] fn nop_ipv6prefix_trie(bencher: &mut Bencher) { let mut result = Vec::with_capacity(1_000_000); bencher.iter(|| result.extend(read_ip::())); println!("{}", result.len()); } #[bench] fn build_ipv4prefix_trie(bencher: &mut Bencher) { let mut trie = RTrieSet::new(); bencher.iter(|| { trie = read_ip::().collect(); }); println!("{}", trie.len()); } #[bench] fn build_ipv4prefix_lctrie(bencher: &mut Bencher) { let mut trie : LCTrieSet<_> = RTrieSet::new().compress(); bencher.iter(|| { trie = read_ip::().collect(); }); println!("{}", trie.len()); } #[bench] fn build_ipv4net_treebit(bencher: &mut Bencher) { let mut trie = IpLookupTable::new(); bencher.iter(|| { trie = read_ip::() .fold(IpLookupTable::::with_capacity(1_000_000), |mut trie,p| { trie.insert(p.network(), p.len() as u32, ()); trie }); }); println!("{}", trie.len()); } #[bench] fn build_ipv6prefix_trie(bencher: &mut Bencher) { let mut trie = RTrieSet::new(); bencher.iter(|| { trie = read_ip::().collect(); }); println!("{}", trie.len()); } #[bench] fn build_ipv6prefix_lctrie(bencher: &mut Bencher) { let mut trie : LCTrieSet<_> = RTrieSet::new().compress(); bencher.iter(|| { trie = read_ip::().collect(); }); println!("{}", trie.len()); } #[bench] fn build_ipv6net_treebit(bencher: &mut Bencher) { let mut trie = IpLookupTable::new(); bencher.iter(|| { trie = read_ip::() .fold(IpLookupTable::::with_capacity(1_000_000), |mut trie,p| { trie.insert(p.network(), p.len() as u32, ()); trie }); }); println!("{}", trie.len()); }