@@ -7,6 +7,7 @@ use deltachat::chatlist::Chatlist;
7
7
use deltachat:: context:: Context ;
8
8
use deltachat:: stock_str:: StockStrings ;
9
9
use deltachat:: Events ;
10
+ use tempfile:: tempdir;
10
11
11
12
async fn get_chat_msgs_benchmark ( dbfile : & Path , chats : & [ ChatId ] ) {
12
13
let id = 100 ;
@@ -19,6 +20,17 @@ async fn get_chat_msgs_benchmark(dbfile: &Path, chats: &[ChatId]) {
19
20
}
20
21
}
21
22
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
+
22
34
fn criterion_benchmark ( c : & mut Criterion ) {
23
35
// To enable this benchmark, set `DELTACHAT_BENCHMARK_DATABASE` to some large database with many
24
36
// messages, such as your primary account.
@@ -34,9 +46,19 @@ fn criterion_benchmark(c: &mut Criterion) {
34
46
( 0 ..len) . map ( |i| chatlist. get_chat_id ( i) . unwrap ( ) ) . collect ( )
35
47
} ) ;
36
48
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
+
38
60
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) ) )
40
62
} ) ;
41
63
} else {
42
64
println ! ( "env var not set: DELTACHAT_BENCHMARK_DATABASE" ) ;
0 commit comments