fn single_insertion()

in benches/azks.rs [21:54]


fn single_insertion(c: &mut Criterion) {
    let num_nodes = 1000;

    let mut rng: ThreadRng = thread_rng();

    let runtime = tokio::runtime::Runtime::new().unwrap();

    let db = InMemoryDb::new();

    let mut azks1 = runtime.block_on(Azks::new::<_, Blake3>(&db)).unwrap();
    for _ in 0..num_nodes {
        let label = NodeLabel::random(&mut rng);
        let mut input = [0u8; 32];
        rng.fill_bytes(&mut input);
        let hash = Blake3::hash(&input);
        runtime
            .block_on(azks1.insert_leaf::<_, Blake3>(&db, Node::<Blake3> { hash, label }))
            .unwrap();
    }

    c.bench_function("single insertion into tree with 1000 nodes", move |b| {
        b.iter(|| {
            let label = NodeLabel::random(&mut rng);
            let mut input = [0u8; 32];
            rng.fill_bytes(&mut input);
            let hash = Blake3::hash(&input);

            let _start = Instant::now();
            runtime
                .block_on(azks1.insert_leaf::<_, Blake3>(&db, Node::<Blake3> { hash, label }))
                .unwrap();
        })
    });
}