benches: Run the async benches on a tokio runtime.

master
Damir Jelić 2021-03-09 14:24:16 +01:00
parent e5585b57e8
commit 91c326e970
2 changed files with 14 additions and 6 deletions

View File

@ -51,7 +51,7 @@ tempfile = "3.2.0"
http = "0.2.3"
matrix-sdk-test = { version = "0.2.0", path = "../matrix_sdk_test" }
indoc = "1.0.3"
criterion = { version = "0.3.4", features = ["async", "async_futures", "html_reports"] }
criterion = { version = "0.3.4", features = ["async", "async_tokio", "html_reports"] }
[target.'cfg(target_os = "linux")'.dev-dependencies]
pprof = { version = "0.4.2", features = ["flamegraph"] }

View File

@ -3,7 +3,7 @@ mod perf;
use std::convert::TryFrom;
use criterion::{async_executor::FuturesExecutor, *};
use criterion::*;
use futures::executor::block_on;
use matrix_sdk_common::{
@ -17,6 +17,7 @@ use matrix_sdk_common::{
use matrix_sdk_crypto::{EncryptionSettings, OlmMachine};
use matrix_sdk_test::response_from_file;
use serde_json::Value;
use tokio::runtime::Builder;
fn alice_id() -> UserId {
user_id!("@alice:example.org")
@ -41,6 +42,9 @@ fn keys_claim_response() -> claim_keys::Response {
}
pub fn keys_query(c: &mut Criterion) {
let runtime = Builder::new_multi_thread()
.build()
.expect("Can't create runtime");
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
let response = keys_query_response();
let uuid = Uuid::new_v4();
@ -62,7 +66,7 @@ pub fn keys_query(c: &mut Criterion) {
BenchmarkId::new("memory store", &name),
&response,
|b, response| {
b.to_async(FuturesExecutor)
b.to_async(&runtime)
.iter(|| async { machine.mark_request_as_sent(&uuid, response).await.unwrap() })
},
);
@ -80,7 +84,7 @@ pub fn keys_query(c: &mut Criterion) {
BenchmarkId::new("sled store", &name),
&response,
|b, response| {
b.to_async(FuturesExecutor)
b.to_async(&runtime)
.iter(|| async { machine.mark_request_as_sent(&uuid, response).await.unwrap() })
},
);
@ -147,6 +151,10 @@ pub fn keys_claiming(c: &mut Criterion) {
}
pub fn room_key_sharing(c: &mut Criterion) {
let runtime = Builder::new_multi_thread()
.build()
.expect("Can't create runtime");
let keys_query_response = keys_query_response();
let uuid = Uuid::new_v4();
let response = keys_claim_response();
@ -169,7 +177,7 @@ pub fn room_key_sharing(c: &mut Criterion) {
let name = format!("{} devices", count);
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
b.to_async(FuturesExecutor).iter(|| async {
b.to_async(&runtime).iter(|| async {
let requests = machine
.share_group_session(&room_id, users.iter(), EncryptionSettings::default())
.await
@ -200,7 +208,7 @@ pub fn room_key_sharing(c: &mut Criterion) {
block_on(machine.mark_request_as_sent(&uuid, &response)).unwrap();
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
b.to_async(FuturesExecutor).iter(|| async {
b.to_async(&runtime).iter(|| async {
let requests = machine
.share_group_session(&room_id, users.iter(), EncryptionSettings::default())
.await