-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathnest.rs
33 lines (26 loc) · 1.06 KB
/
nest.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);