|
| 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