Skip to content

Commit

Permalink
restore router bench
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Nov 12, 2020
1 parent d32e638 commit 0a86455
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: check
args: --benches --features __internal__bench
args: --benches

- name: tests
uses: actions-rs/cargo@v1
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ logger = ["femme"]
docs = ["unstable"]
sessions = ["async-session", "cookies"]
unstable = []
# DO NOT USE. Only exists to expose internals so they can be benchmarked.
__internal__bench = []

[dependencies]
async-h1 = { version = "2.1.2", optional = true }
Expand Down
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, Request, Response, Url};

// 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);
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@
//! See more examples in the [examples](https://github.com/http-rs/tide/tree/main/examples) directory.

#![cfg_attr(feature = "docs", feature(doc_cfg))]
#![forbid(unsafe_code, rust_2018_idioms)]
#![forbid(unsafe_code)]
#![deny(missing_debug_implementations, nonstandard_style)]
#![warn(missing_docs, unreachable_pub, future_incompatible)]
#![warn(missing_docs, unreachable_pub, future_incompatible, rust_2018_idioms)]
#![doc(test(attr(deny(warnings))))]
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
#![doc(html_favicon_url = "https://yoshuawuyts.com/assets/http-rs/favicon.ico")]
#![doc(html_logo_url = "https://yoshuawuyts.com/assets/http-rs/logo-rounded.png")]

Expand Down
5 changes: 3 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,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 0a86455

Please sign in to comment.