From ed3e766b81bf2e6dc9437fd91058c5a016cefd81 Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Tue, 5 Jul 2022 12:41:15 -0400 Subject: [PATCH] add sending benchmark --- Cargo.toml | 5 +++++ benches/benches.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 benches/benches.rs diff --git a/Cargo.toml b/Cargo.toml index a526eb0..f5ec204 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,13 @@ tracing = { version = "0.1.35", features = ["log"] } [dev-dependencies] anyhow = "1.0.56" async-tungstenite = { version = "0.17.1", features = ["tokio-runtime"] } +criterion = { version = "0.3.5", features = ["async_tokio"] } matches = "0.1.8" reqwest = { version = "0.11.7" } tempfile = "3.1.0" tokio = { version = "1.14.0", features = ["rt", "macros", "net"] } tokio-test = "0.4.2" + +[[bench]] +name = "benches" +harness = false diff --git a/benches/benches.rs b/benches/benches.rs new file mode 100644 index 0000000..dc52e16 --- /dev/null +++ b/benches/benches.rs @@ -0,0 +1,44 @@ +use criterion::BenchmarkId; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use tokio::runtime; + +use aurelius::Server; + +fn from_elem(c: &mut Criterion) { + let size: usize = 1024; + + c.bench_with_input(BenchmarkId::new("small send", size), &size, |b, _| { + let runtime = runtime::Builder::new_current_thread() + .enable_io() + .build() + .unwrap(); + + let addr = "127.0.0.1:0".parse().unwrap(); + + let server = runtime.block_on(async { Server::bind(&addr).await.unwrap() }); + + b.to_async(&runtime).iter(|| async { + server.send(black_box("Hello, world!")).await.unwrap(); + }); + }); + + c.bench_with_input(BenchmarkId::new("large send", size), &size, |b, _| { + let runtime = runtime::Builder::new_current_thread() + .enable_io() + .build() + .unwrap(); + + let addr = "127.0.0.1:0".parse().unwrap(); + + let server = runtime.block_on(async { Server::bind(&addr).await.unwrap() }); + + let markdown = "a ".repeat(100_000); + + b.to_async(&runtime).iter(|| async { + server.send(black_box(&markdown)).await.unwrap(); + }); + }); +} + +criterion_group!(benches, from_elem); +criterion_main!(benches);