Benchmark for read_tls with polled nbio

This commit is contained in:
Joseph Birr-Pixton 2019-04-22 12:10:32 +01:00
parent e18e999c4a
commit 16f9743a75
3 changed files with 48 additions and 0 deletions

View File

@ -29,6 +29,7 @@ env_logger = "0.6.1"
log = "0.4.0"
tempfile = "3.0"
webpki-roots = "0.16"
criterion = "0.2"
[[example]]
name = "bogo_shim"
@ -42,3 +43,8 @@ path = "examples/internal/trytls_shim.rs"
[[example]]
name = "bench"
path = "examples/internal/bench.rs"
[[bench]]
name = "benchmarks"
path = "tests/benchmarks.rs"
harness = false

26
tests/benchmarks.rs Normal file
View File

@ -0,0 +1,26 @@
/// Microbenchmarks go here. Larger benchmarks of (eg.) protocol
/// performance go in examples/internal/bench.rs.
use criterion::Criterion;
use criterion::criterion_group;
use criterion::criterion_main;
#[allow(dead_code)]
mod common;
use crate::common::*;
use rustls::{Session, ServerSession};
use std::sync::Arc;
use std::io;
fn bench_ewouldblock(c: &mut Criterion) {
let server_config = make_server_config(KeyType::RSA);
let mut server = ServerSession::new(&Arc::new(server_config));
let mut read_ewouldblock = FailsReads::new(io::ErrorKind::WouldBlock);
c.bench_function("read_tls with EWOULDBLOCK",
move |b| b.iter(|| server.read_tls(&mut read_ewouldblock)));
}
criterion_group!(benches, bench_ewouldblock);
criterion_main!(benches);

View File

@ -274,3 +274,19 @@ pub fn do_handshake_until_error(client: &mut ClientSession,
pub fn dns_name(name: &'static str) -> webpki::DNSNameRef<'_> {
webpki::DNSNameRef::try_from_ascii_str(name).unwrap()
}
pub struct FailsReads {
errkind: io::ErrorKind
}
impl FailsReads {
pub fn new(errkind: io::ErrorKind) -> FailsReads {
FailsReads { errkind }
}
}
impl io::Read for FailsReads {
fn read(&mut self, _b: &mut [u8]) -> io::Result<usize> {
Err(io::Error::from(self.errkind))
}
}