From 8af47de5a4b8ebf27ae942d5be7ce6e78b7694dd Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 16 Apr 2021 23:02:24 +0300 Subject: [PATCH] Benchmark adding 500 contacts from address book --- Cargo.toml | 4 ++++ benches/contacts.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 benches/contacts.rs diff --git a/Cargo.toml b/Cargo.toml index 46bedac6d..ad70e49b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,6 +103,10 @@ required-features = ["repl"] name = "create_account" harness = false +[[bench]] +name = "contacts" +harness = false + [features] default = [] internals = [] diff --git a/benches/contacts.rs b/benches/contacts.rs new file mode 100644 index 000000000..41d5c624b --- /dev/null +++ b/benches/contacts.rs @@ -0,0 +1,30 @@ +use async_std::task::block_on; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use deltachat::contact::Contact; +use deltachat::context::Context; +use tempfile::tempdir; + +async fn address_book_benchmark(n: u32) { + let dir = tempdir().unwrap(); + let dbfile = dir.path().join("db.sqlite"); + let id = 100; + let context = Context::new("FakeOS".into(), dbfile.into(), id) + .await + .unwrap(); + + let book = (0..n) + .map(|i| format!("Name {}\naddr{}@example.org\n", i, i)) + .collect::>() + .join(""); + + Contact::add_address_book(&context, book).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 })) + }); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches);