#![feature(test, plugin)] #![plugin(rocket_codegen)] extern crate rocket; use rocket::config::{Environment, Config}; #[get("/", format = "application/json")] fn get() -> &'static str { "get" } #[post("/", format = "application/json")] fn post() -> &'static str { "post" } fn rocket() -> rocket::Rocket { let config = Config::new(Environment::Production).unwrap(); rocket::custom(config, false) .mount("/", routes![get, post]) } #[cfg(feature = "testing")] mod benches { extern crate test; use super::rocket; use self::test::Bencher; use rocket::testing::MockRequest; use rocket::http::Method::*; use rocket::http::ContentType; #[bench] fn content_type_format(b: &mut Bencher) { let rocket = rocket(); let mut request = MockRequest::new(Post, "/").header(ContentType::JSON); b.iter(|| { request.dispatch_with(&rocket); }); } #[bench] fn wrong_content_type_format(b: &mut Bencher) { let rocket = rocket(); let mut request = MockRequest::new(Post, "/").header(ContentType::Plain); b.iter(|| { request.dispatch_with(&rocket); }); } }