Skip to content

Commit

Permalink
add sending benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed Jul 5, 2022
1 parent e97afd7 commit ed3e766
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 44 additions & 0 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit ed3e766

Please sign in to comment.