This repository has no description
1use divan::Bencher;
2use divan::counter::ItemsCount;
3use knot_bench::{OpenLatency, RepoCount, build_registry, replay_boot};
4use knot_types::RepoDid;
5
6#[global_allocator]
7static ALLOC: divan::AllocProfiler = divan::AllocProfiler::system();
8
9const FABRIC_OPEN_MICROS: u64 = 200;
10
11fn repo_counts() -> Vec<u64> {
12 let Ok(raw) = std::env::var("KNOT_BENCH_REPOS") else {
13 return vec![1, 1000];
14 };
15 let counts: Vec<u64> = raw
16 .split(',')
17 .map(str::trim)
18 .filter(|entry| !entry.is_empty())
19 .map(|entry| {
20 entry
21 .parse::<u64>()
22 .unwrap_or_else(|_| panic!("KNOT_BENCH_REPOS entry {entry:?} is not a repo count"))
23 })
24 .collect();
25 assert!(
26 !counts.is_empty(),
27 "KNOT_BENCH_REPOS is set but lists no repo counts"
28 );
29 counts
30}
31
32fn main() {
33 divan::main();
34}
35
36#[divan::bench(args = repo_counts())]
37fn boot(bencher: Bencher, repos: u64) {
38 let registry = build_registry(RepoCount::new(repos));
39 bencher
40 .counter(ItemsCount::new(registry.dids().len()))
41 .bench_local(|| registry.index().rebuild().unwrap());
42}
43
44#[divan::bench(args = repo_counts())]
45fn boot_fabric(bencher: Bencher, repos: u64) {
46 let registry = build_registry(RepoCount::new(repos));
47 let dids: Vec<RepoDid> = registry.dids().to_vec();
48 bencher
49 .counter(ItemsCount::new(dids.len()))
50 .bench_local(|| {
51 let index = registry.index();
52 replay_boot(&index, &dids, OpenLatency::micros(FABRIC_OPEN_MICROS));
53 });
54}