Skip to content

Commit 6801e3d

Browse files
committed
Write simple benchmark
1 parent c667949 commit 6801e3d

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

benches/get_chat_msgs.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use deltachat::chatlist::Chatlist;
77
use deltachat::context::Context;
88
use deltachat::stock_str::StockStrings;
99
use deltachat::Events;
10+
use tempfile::tempdir;
1011

1112
async fn get_chat_msgs_benchmark(dbfile: &Path, chats: &[ChatId]) {
1213
let id = 100;
@@ -19,6 +20,17 @@ async fn get_chat_msgs_benchmark(dbfile: &Path, chats: &[ChatId]) {
1920
}
2021
}
2122

23+
async fn marknoticed_chat_benchmark(dbfile: &Path, chats: &[ChatId]) {
24+
let id = 100;
25+
let context = Context::new(dbfile, id, Events::new(), StockStrings::new())
26+
.await
27+
.unwrap();
28+
29+
for c in chats.iter().take(20) {
30+
black_box(chat::marknoticed_chat(&context, *c).await.unwrap());
31+
}
32+
}
33+
2234
fn criterion_benchmark(c: &mut Criterion) {
2335
// To enable this benchmark, set `DELTACHAT_BENCHMARK_DATABASE` to some large database with many
2436
// messages, such as your primary account.
@@ -34,9 +46,19 @@ fn criterion_benchmark(c: &mut Criterion) {
3446
(0..len).map(|i| chatlist.get_chat_id(i).unwrap()).collect()
3547
});
3648

37-
c.bench_function("chat::get_chat_msgs (load messages from 10 chats)", |b| {
49+
// c.bench_function("chat::get_chat_msgs (load messages from 10 chats)", |b| {
50+
// b.to_async(&rt)
51+
// .iter(|| get_chat_msgs_benchmark(black_box(path.as_ref()), black_box(&chats)))
52+
// });
53+
54+
c.bench_function("chat::marknoticed_chat (mark 10 chats as noticed)", |b| {
55+
let dir = tempdir().unwrap();
56+
let dir = dir.path();
57+
let new_db = dir.join("dc.db");
58+
std::fs::copy(&path, &new_db).unwrap();
59+
3860
b.to_async(&rt)
39-
.iter(|| get_chat_msgs_benchmark(black_box(path.as_ref()), black_box(&chats)))
61+
.iter(|| marknoticed_chat_benchmark(black_box(new_db.as_ref()), black_box(&chats)))
4062
});
4163
} else {
4264
println!("env var not set: DELTACHAT_BENCHMARK_DATABASE");

0 commit comments

Comments
 (0)