From 80a1abdc890b63930ab1d29ac4b66cb70a5a5866 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 19 May 2017 19:39:10 -0700 Subject: [PATCH] Add hello_world benchmark. --- lib/benches/format-routing.rs | 1 - lib/benches/ranked-routing.rs | 1 - lib/benches/simple-routing.rs | 22 +++++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/benches/format-routing.rs b/lib/benches/format-routing.rs index 362b829d..1bb137bf 100644 --- a/lib/benches/format-routing.rs +++ b/lib/benches/format-routing.rs @@ -4,7 +4,6 @@ extern crate rocket; use rocket::config::{Environment, Config}; -use rocket::http::RawStr; #[get("/", format = "application/json")] fn get() -> &'static str { "get" } diff --git a/lib/benches/ranked-routing.rs b/lib/benches/ranked-routing.rs index 1caef283..4c7231b9 100644 --- a/lib/benches/ranked-routing.rs +++ b/lib/benches/ranked-routing.rs @@ -4,7 +4,6 @@ extern crate rocket; use rocket::config::{Environment, Config}; -use rocket::http::RawStr; #[get("/", format = "application/json")] fn get() -> &'static str { "json" } diff --git a/lib/benches/simple-routing.rs b/lib/benches/simple-routing.rs index be4d9cce..92b38144 100644 --- a/lib/benches/simple-routing.rs +++ b/lib/benches/simple-routing.rs @@ -1,11 +1,16 @@ #![feature(test, plugin)] #![plugin(rocket_codegen)] +// #![feature(alloc_system)] +// extern crate alloc_system; extern crate rocket; use rocket::config::{Environment, Config}; use rocket::http::RawStr; +#[get("/")] +fn hello_world() -> &'static str { "Hello, world!" } + #[get("/")] fn get_index() -> &'static str { "index" } @@ -27,6 +32,11 @@ fn index_c() -> &'static str { "index" } #[get("/")] fn index_dyn_a(a: &RawStr) -> &'static str { "index" } +fn hello_world_rocket() -> rocket::Rocket { + let config = Config::new(Environment::Production).unwrap(); + rocket::custom(config, false).mount("/", routes![hello_world]) +} + fn rocket() -> rocket::Rocket { let config = Config::new(Environment::Production).unwrap(); rocket::custom(config, false) @@ -37,11 +47,21 @@ fn rocket() -> rocket::Rocket { mod benches { extern crate test; - use super::rocket; + use super::{hello_world_rocket, rocket}; use self::test::Bencher; use rocket::testing::MockRequest; use rocket::http::Method::*; + #[bench] + fn bench_hello_world(b: &mut Bencher) { + let rocket = hello_world_rocket(); + let mut request = MockRequest::new(Get, "/"); + + b.iter(|| { + request.dispatch_with(&rocket); + }); + } + #[bench] fn bench_single_get_index(b: &mut Bencher) { let rocket = rocket();