mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
Add send_events benchmark
This commit is contained in:
@@ -137,6 +137,10 @@ harness = false
|
|||||||
name = "get_chatlist"
|
name = "get_chatlist"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "send_events"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["vendored"]
|
default = ["vendored"]
|
||||||
internals = []
|
internals = []
|
||||||
|
|||||||
42
benches/send_events.rs
Normal file
42
benches/send_events.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
use criterion::async_executor::AsyncStdExecutor;
|
||||||
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
|
use deltachat::context::Context;
|
||||||
|
use deltachat::{info, Event, EventType};
|
||||||
|
use tempfile::tempdir;
|
||||||
|
|
||||||
|
async fn send_events_benchmark(context: &Context) {
|
||||||
|
let emitter = context.get_event_emitter();
|
||||||
|
for _i in 0..1_000_000 {
|
||||||
|
info!(context, "interesting event...");
|
||||||
|
}
|
||||||
|
info!(context, "DONE");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match emitter.recv().await.unwrap() {
|
||||||
|
Event {
|
||||||
|
typ: EventType::Info(info),
|
||||||
|
..
|
||||||
|
} if info.contains("DONE") => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
|
let dir = tempdir().unwrap();
|
||||||
|
let dbfile = dir.path().join("db.sqlite");
|
||||||
|
let id = 100;
|
||||||
|
let context =
|
||||||
|
async_std::task::block_on(async { Context::new(dbfile.into(), id).await.unwrap() });
|
||||||
|
|
||||||
|
c.bench_function("Sending 1000 events", |b| {
|
||||||
|
b.to_async(AsyncStdExecutor)
|
||||||
|
.iter(|| send_events_benchmark(&context))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, criterion_benchmark);
|
||||||
|
criterion_main!(benches);
|
||||||
@@ -441,14 +441,13 @@ impl Context {
|
|||||||
async_std::task::spawn(async move {
|
async_std::task::spawn(async move {
|
||||||
// TODO synchronously is prob. better
|
// TODO synchronously is prob. better
|
||||||
match context.get_config_int(Config::DebugLogging).await {
|
match context.get_config_int(Config::DebugLogging).await {
|
||||||
Err(e) => eprintln!("Can't get debug logging config: {:#}", e),
|
Err(_) => {} // Probably the database is simply closed (i.e. encrypted and no passphrase available yet)
|
||||||
Ok(0) => {}
|
Ok(0) => {}
|
||||||
Ok(debug_logging_webxdc) => {
|
Ok(debug_logging_webxdc) => {
|
||||||
let time = SystemTime::now()
|
let time = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.as_millis() as i64;
|
.as_millis() as i64;
|
||||||
// TODO
|
|
||||||
|
|
||||||
let webxdc_instance_id = MsgId::new(debug_logging_webxdc as u32);
|
let webxdc_instance_id = MsgId::new(debug_logging_webxdc as u32);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user