message: chore: fix peer_store bench warning
diff: @@ -5,42 +5,56 @@ extern crate ckb_network;
  extern crate ckb_util;
  use ckb_network::{multiaddr::Multiaddr, peer_store::PeerStore, PeerId};
  -use criterion::Criterion;
  +use criterion::{BatchSize, BenchmarkId, Criterion};
  -fn insert_benchmark(c: &mut Criterion) {
  - c.bench_function_over_inputs(
  - "Peer store insert addrs",
  - |b, &&size| {
  - let peer_ids = (0..size).map(|_| PeerId::random()).collect::<Vec<_>>();
  +const SIZES: &[usize] = &[10_000, 20_000];
  +
  +fn bench(c: &mut Criterion) {
  + let mut group = c.benchmark_group("peer_store");
  +
  + for size in SIZES.iter() {
  + group.bench_with_input(BenchmarkId::new("add_addr", size), size, |b, i| {
  + b.iter_batched(
  + || {
  + let peer_ids = (0..*i).map(|_| PeerId::random()).collect::<Vec<_>>();
  let addr = "/ip4/255.0.0.1/tcp/42".parse::<Multiaddr>().unwrap();
  - b.iter(|| {
  + (peer_ids, addr)
  + },
  + |(peer_ids, addr)| {
  let mut peer_store = PeerStore::default();
  for peer_id in peer_ids.clone() {
  peer_store.add_addr(peer_id, addr.clone()).unwrap();
  }
  - });
  },
  - &[10_000, 20_000],
  - );
  + BatchSize::PerIteration,
  + )
  + });
  }
  -fn get_random_benchmark(c: &mut Criterion) {
  - c.bench_function_over_inputs(
  - "Peer store get random addrs",
  - |b, &&size| {
  - let peer_ids = (0..size).map(|_| PeerId::random()).collect::<Vec<_>>();
  + for size in SIZES.iter() {
  + group.bench_with_input(
  + BenchmarkId::new("fetch_random_addrs", size),
  + size,
  + |b, i| {
  + b.iter_batched(
  + || {
  + let peer_ids = (0..*i).map(|_| PeerId::random()).collect::<Vec<_>>();
  let addr = "/ip4/255.0.0.1/tcp/42".parse::<Multiaddr>().unwrap();
  let mut peer_store = PeerStore::default();
  for peer_id in peer_ids {
  peer_store.add_addr(peer_id, addr.clone()).unwrap();
  }
  - b.iter(|| {
  - peer_store.fetch_random_addrs(size);
  - });
  + peer_store
  + },
  + |mut peer_store| {
  + peer_store.fetch_random_addrs(*i);
  + },
  + BatchSize::PerIteration,
  + )
  },
  - &[10_000, 20_000],
  );
  }
  +}
  -criterion_group!(benches, insert_benchmark, get_random_benchmark);
  +criterion_group!(benches, bench);
  criterion_main!(benches);
  