Benchmark adding 500 contacts from address book

This commit is contained in:
link2xt
2021-04-16 23:02:24 +03:00
parent c7345c16f8
commit 8af47de5a4
2 changed files with 34 additions and 0 deletions

View File

@@ -103,6 +103,10 @@ required-features = ["repl"]
name = "create_account"
harness = false
[[bench]]
name = "contacts"
harness = false
[features]
default = []
internals = []

30
benches/contacts.rs Normal file
View File

@@ -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::<Vec<String>>()
.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);