|
1 | | -// use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
2 | | -// use http_types::Method; |
3 | | -// use tide::router::Router; |
| 1 | +use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 2 | +use http_types::{Method, Request, Response, Url}; |
4 | 3 |
|
5 | | -// fn criterion_benchmark(c: &mut Criterion) { |
6 | | -// let mut router = Router::<()>::new(); |
7 | | -// router.add( |
8 | | -// "hello", |
9 | | -// Method::Get, |
10 | | -// Box::new(|_| async { Ok("hello world") }), |
11 | | -// ); |
| 4 | +fn criterion_benchmark(c: &mut Criterion) { |
| 5 | + let mut app = tide::new(); |
| 6 | + app.at("/hello").get(|_| async { Ok("hello world") }); |
12 | 7 |
|
13 | | -// c.bench_function("route-match", |b| { |
14 | | -// b.iter(|| black_box(router.route("/hello", Method::Get))) |
15 | | -// }); |
| 8 | + let route = Url::parse("https://example.com/hello").unwrap(); |
| 9 | + let req = Request::new(Method::Get, route); |
| 10 | + c.bench_function("route-match", |b| { |
| 11 | + b.iter(|| black_box(app.respond::<_, Response>(req.clone()))); |
| 12 | + }); |
16 | 13 |
|
17 | | -// c.bench_function("route-root", |b| { |
18 | | -// b.iter(|| black_box(router.route("", Method::Get))) |
19 | | -// }); |
20 | | -// } |
| 14 | + let route = Url::parse("https://example.com").unwrap(); |
| 15 | + let req = Request::new(Method::Get, route); |
| 16 | + c.bench_function("route-root", |b| { |
| 17 | + b.iter(|| black_box(app.respond::<_, Response>(req.clone()))); |
| 18 | + }); |
| 19 | +} |
21 | 20 |
|
22 | | -// criterion_group!(benches, criterion_benchmark); |
23 | | -// criterion_main!(benches); |
24 | | - |
25 | | -fn main() {} |
| 21 | +criterion_group!(benches, criterion_benchmark); |
| 22 | +criterion_main!(benches); |
0 commit comments