From 91c326e9701ac326f645d6dedda14459024c2206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 9 Mar 2021 14:24:16 +0100 Subject: [PATCH] benches: Run the async benches on a tokio runtime. --- matrix_sdk_crypto/Cargo.toml | 2 +- matrix_sdk_crypto/benches/crypto_bench.rs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/matrix_sdk_crypto/Cargo.toml b/matrix_sdk_crypto/Cargo.toml index 15bcf1e2..c72497ab 100644 --- a/matrix_sdk_crypto/Cargo.toml +++ b/matrix_sdk_crypto/Cargo.toml @@ -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"] } diff --git a/matrix_sdk_crypto/benches/crypto_bench.rs b/matrix_sdk_crypto/benches/crypto_bench.rs index de0134f9..3f61feca 100644 --- a/matrix_sdk_crypto/benches/crypto_bench.rs +++ b/matrix_sdk_crypto/benches/crypto_bench.rs @@ -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