From 6d4ec75a7bf590fe4cd0adf9bfa7c69d12ae31e7 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 17 Apr 2021 18:40:40 +0300 Subject: [PATCH] Benchmark reading contact list --- benches/contacts.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/benches/contacts.rs b/benches/contacts.rs index 41d5c624b..6820d7183 100644 --- a/benches/contacts.rs +++ b/benches/contacts.rs @@ -4,7 +4,7 @@ use deltachat::contact::Contact; use deltachat::context::Context; use tempfile::tempdir; -async fn address_book_benchmark(n: u32) { +async fn address_book_benchmark(n: u32, read_count: u32) { let dir = tempdir().unwrap(); let dbfile = dir.path().join("db.sqlite"); let id = 100; @@ -18,11 +18,20 @@ async fn address_book_benchmark(n: u32) { .join(""); Contact::add_address_book(&context, book).await.unwrap(); + + let query: Option<&str> = None; + for _ in 0..read_count { + Contact::get_all(&context, 0, query).await.unwrap(); + } } fn criterion_benchmark(c: &mut Criterion) { c.bench_function("create 500 contacts", |b| { - b.iter(|| block_on(async { address_book_benchmark(black_box(500)).await })) + b.iter(|| block_on(async { address_book_benchmark(black_box(500), black_box(0)).await })) + }); + + c.bench_function("create 100 contacts and read it 1000 times", |b| { + b.iter(|| block_on(async { address_book_benchmark(black_box(100), black_box(1000)).await })) }); }