benches: Fix the key claiming bench, it needs to run under tokio now

master
Damir Jelić 2021-03-11 13:28:22 +01:00
parent daf313e358
commit a32f9187e6
1 changed files with 41 additions and 22 deletions

View File

@ -1,11 +1,10 @@
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
mod perf; mod perf;
use std::convert::TryFrom; use std::{convert::TryFrom, sync::Arc};
use criterion::*; use criterion::*;
use futures::executor::block_on;
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::{ api::r0::{
keys::{claim_keys, get_keys}, keys::{claim_keys, get_keys},
@ -94,6 +93,12 @@ pub fn keys_query(c: &mut Criterion) {
} }
pub fn keys_claiming(c: &mut Criterion) { pub fn keys_claiming(c: &mut Criterion) {
let runtime = Arc::new(
Builder::new_multi_thread()
.build()
.expect("Can't create runtime"),
);
let keys_query_response = keys_query_response(); let keys_query_response = keys_query_response();
let uuid = Uuid::new_v4(); let uuid = Uuid::new_v4();
@ -116,10 +121,16 @@ pub fn keys_claiming(c: &mut Criterion) {
b.iter_batched( b.iter_batched(
|| { || {
let machine = OlmMachine::new(&alice_id(), &alice_device_id()); let machine = OlmMachine::new(&alice_id(), &alice_device_id());
block_on(machine.mark_request_as_sent(&uuid, &keys_query_response)).unwrap(); runtime
machine .block_on(machine.mark_request_as_sent(&uuid, &keys_query_response))
.unwrap();
(machine, runtime.clone())
},
move |(machine, runtime)| {
runtime
.block_on(machine.mark_request_as_sent(&uuid, response))
.unwrap()
}, },
move |machine| block_on(machine.mark_request_as_sent(&uuid, response)).unwrap(),
BatchSize::SmallInput, BatchSize::SmallInput,
) )
}, },
@ -132,17 +143,24 @@ pub fn keys_claiming(c: &mut Criterion) {
b.iter_batched( b.iter_batched(
|| { || {
let dir = tempfile::tempdir().unwrap(); let dir = tempfile::tempdir().unwrap();
let machine = block_on(OlmMachine::new_with_default_store( let machine = runtime
&alice_id(), .block_on(OlmMachine::new_with_default_store(
&alice_device_id(), &alice_id(),
dir.path(), &alice_device_id(),
None, dir.path(),
)) None,
.unwrap(); ))
block_on(machine.mark_request_as_sent(&uuid, &keys_query_response)).unwrap(); .unwrap();
machine runtime
.block_on(machine.mark_request_as_sent(&uuid, &keys_query_response))
.unwrap();
(machine, runtime.clone())
},
move |(machine, runtime)| {
runtime
.block_on(machine.mark_request_as_sent(&uuid, response))
.unwrap()
}, },
move |machine| block_on(machine.mark_request_as_sent(&uuid, response)).unwrap(),
BatchSize::SmallInput, BatchSize::SmallInput,
) )
}, },
@ -202,13 +220,14 @@ pub fn room_key_sharing(c: &mut Criterion) {
}); });
let dir = tempfile::tempdir().unwrap(); let dir = tempfile::tempdir().unwrap();
let machine = block_on(OlmMachine::new_with_default_store( let machine = runtime
&alice_id(), .block_on(OlmMachine::new_with_default_store(
&alice_device_id(), &alice_id(),
dir.path(), &alice_device_id(),
None, dir.path(),
)) None,
.unwrap(); ))
.unwrap();
runtime runtime
.block_on(machine.mark_request_as_sent(&uuid, &keys_query_response)) .block_on(machine.mark_request_as_sent(&uuid, &keys_query_response))
.unwrap(); .unwrap();