Skip to content

Commit 0a86455

Browse files
committed
restore router bench
1 parent d32e638 commit 0a86455

5 files changed

Lines changed: 26 additions & 28 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
uses: actions-rs/cargo@v1
5757
with:
5858
command: check
59-
args: --benches --features __internal__bench
59+
args: --benches
6060

6161
- name: tests
6262
uses: actions-rs/cargo@v1

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ logger = ["femme"]
3131
docs = ["unstable"]
3232
sessions = ["async-session", "cookies"]
3333
unstable = []
34-
# DO NOT USE. Only exists to expose internals so they can be benchmarked.
35-
__internal__bench = []
3634

3735
[dependencies]
3836
async-h1 = { version = "2.1.2", optional = true }

benches/router.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
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};
43

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") });
127

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+
});
1613

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+
}
2120

22-
// criterion_group!(benches, criterion_benchmark);
23-
// criterion_main!(benches);
24-
25-
fn main() {}
21+
criterion_group!(benches, criterion_benchmark);
22+
criterion_main!(benches);

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353
//! See more examples in the [examples](https://github.com/http-rs/tide/tree/main/examples) directory.
5454
5555
#![cfg_attr(feature = "docs", feature(doc_cfg))]
56-
#![forbid(unsafe_code, rust_2018_idioms)]
56+
#![forbid(unsafe_code)]
5757
#![deny(missing_debug_implementations, nonstandard_style)]
58-
#![warn(missing_docs, unreachable_pub, future_incompatible)]
58+
#![warn(missing_docs, unreachable_pub, future_incompatible, rust_2018_idioms)]
59+
#![doc(test(attr(deny(warnings))))]
60+
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
5961
#![doc(html_favicon_url = "https://yoshuawuyts.com/assets/http-rs/favicon.ico")]
6062
#![doc(html_logo_url = "https://yoshuawuyts.com/assets/http-rs/logo-rounded.png")]
6163

src/server.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ impl<State: Clone + Send + Sync + 'static> Server<State> {
213213
/// #
214214
/// # Ok(()) }
215215
/// ```
216-
pub async fn respond<R>(&self, req: impl Into<http_types::Request>) -> http_types::Result<R>
216+
pub async fn respond<Req, Res>(&self, req: Req) -> http_types::Result<Res>
217217
where
218-
R: From<http_types::Response>,
218+
Req: Into<http_types::Request>,
219+
Res: From<http_types::Response>,
219220
{
220221
let req = req.into();
221222
let Self {

0 commit comments

Comments
 (0)