Skip to content

Commit eb20731

Browse files
committed
Add benchmark for nested routers
1 parent 1d6f120 commit eb20731

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ required-features = ["sessions"]
7979
name = "router"
8080
harness = false
8181

82+
[[bench]]
83+
name = "nest"
84+
harness = false
85+
8286
[[example]]
8387
name = "cookies"
8488
required-features = ["cookies"]

benches/nest.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use http_types::{Method, Request, Response, Url};
3+
4+
fn criterion_benchmark(c: &mut Criterion) {
5+
let mut app = tide::new();
6+
app.at("/x").get(|_| async { Ok("X") });
7+
app.at("/x/y").get(|_| async { Ok("Y") });
8+
app.at("/x/y/z").get(|_| async { Ok("Z") });
9+
10+
let route = Url::parse("https://example.com/x/y/z").unwrap();
11+
let req = Request::new(Method::Get, route);
12+
c.bench_function("plain", |b| {
13+
b.iter(|| black_box(app.respond::<_, Response>(req.clone())));
14+
});
15+
16+
let mut appz = tide::new();
17+
appz.at("/z").get(|_| async { Ok("Z") });
18+
19+
let mut appy = tide::new();
20+
appy.at("/y").nest(appz);
21+
22+
let mut appx = tide::new();
23+
appx.at("/x").nest(appy);
24+
25+
let route = Url::parse("https://example.com/x/y/z").unwrap();
26+
let req = Request::new(Method::Get, route);
27+
c.bench_function("nested", |b| {
28+
b.iter(|| black_box(appx.respond::<_, Response>(req.clone())));
29+
});
30+
}
31+
32+
criterion_group!(benches, criterion_benchmark);
33+
criterion_main!(benches);

0 commit comments

Comments
 (0)