Skip to content

Commit

Permalink
Merge pull request #856 from sorcix/bench-nested
Browse files Browse the repository at this point in the history
Add benchmark for nested routers
  • Loading branch information
yoshuawuyts authored Oct 26, 2021
2 parents 1d6f120 + b5a7dc0 commit 4be9062
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ required-features = ["sessions"]
name = "router"
harness = false

[[bench]]
name = "nest"
harness = false

[[example]]
name = "cookies"
required-features = ["cookies"]
Expand Down
33 changes: 33 additions & 0 deletions benches/nest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use http_types::{Method, Request, Response, Url};

fn criterion_benchmark(c: &mut Criterion) {
let mut app = tide::new();
app.at("/x").get(|_| async { Ok("X") });
app.at("/x/y").get(|_| async { Ok("Y") });
app.at("/x/y/z").get(|_| async { Ok("Z") });

let route = Url::parse("https://example.com/x/y/z").unwrap();
let req = Request::new(Method::Get, route);
c.bench_function("plain", |b| {
b.iter(|| black_box(app.respond::<_, Response>(req.clone())));
});

let mut appz = tide::new();
appz.at("/z").get(|_| async { Ok("Z") });

let mut appy = tide::new();
appy.at("/y").nest(appz);

let mut appx = tide::new();
appx.at("/x").nest(appy);

let route = Url::parse("https://example.com/x/y/z").unwrap();
let req = Request::new(Method::Get, route);
c.bench_function("nested", |b| {
b.iter(|| black_box(appx.respond::<_, Response>(req.clone())));
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

0 comments on commit 4be9062

Please sign in to comment.