Skip to content

Commit

Permalink
restore router bench
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Sep 27, 2020
1 parent 798a247 commit 4ff4b10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
39 changes: 18 additions & 21 deletions benches/router.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// use criterion::{black_box, criterion_group, criterion_main, Criterion};
// use http_types::Method;
// use tide::router::Router;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use http_types::{Method, Url, Request, Response};

// fn criterion_benchmark(c: &mut Criterion) {
// let mut router = Router::<()>::new();
// router.add(
// "hello",
// Method::Get,
// Box::new(|_| async { Ok("hello world") }),
// );
fn criterion_benchmark(c: &mut Criterion) {
let mut app = tide::new();
app.at("/hello").get(|_| async { Ok("hello world") });

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

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

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

fn main() {}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
5 changes: 3 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ impl<State: Clone + Send + Sync + 'static> Server<State> {
/// #
/// # Ok(()) }
/// ```
pub async fn respond<R>(&self, req: impl Into<http_types::Request>) -> http_types::Result<R>
pub async fn respond<Req, Res>(&self, req: Req) -> http_types::Result<Res>
where
R: From<http_types::Response>,
Req: Into<http_types::Request>,
Res: From<http_types::Response>,
{
let req = req.into();
let Self {
Expand Down

0 comments on commit 4ff4b10

Please sign in to comment.