Skip to content

Commit

Permalink
temp disable bench code
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Sep 26, 2020
1 parent c080d97 commit 5065aa9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
40 changes: 21 additions & 19 deletions benches/router.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
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;
// use tide::router::Router;

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 router = Router::<()>::new();
// router.add(
// "hello",
// Method::Get,
// Box::new(|_| async { Ok("hello world") }),
// );

c.bench_function("route-match", |b| {
b.iter(|| black_box(router.route("/hello", Method::Get)))
});
// c.bench_function("route-match", |b| {
// b.iter(|| black_box(router.route("/hello", Method::Get)))
// });

c.bench_function("route-root", |b| {
b.iter(|| black_box(router.route("", Method::Get)))
});
}
// c.bench_function("route-root", |b| {
// b.iter(|| black_box(router.route("", Method::Get)))
// });
// }

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

fn main() {}
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,9 @@ mod request;
mod response;
mod response_builder;
mod route;
mod router;
mod server;

// Expose the router for benchmarking only.
#[doc(hidden)]
pub mod router;

pub mod convert;
pub mod listener;
pub mod log;
Expand Down
7 changes: 6 additions & 1 deletion src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ impl<State: Clone + Send + Sync + 'static> Router<State> {
}
}

pub(crate) fn add(&mut self, path: &str, method: http_types::Method, ep: Box<DynEndpoint<State>>) {
pub(crate) fn add(
&mut self,
path: &str,
method: http_types::Method,
ep: Box<DynEndpoint<State>>,
) {
self.method_map
.entry(method)
.or_insert_with(MethodRouter::new)
Expand Down

0 comments on commit 5065aa9

Please sign in to comment.