Backport benchmarks.

This commit is contained in:
Sergio Benitez 2017-04-23 00:26:19 -07:00
parent 7fa99b75dd
commit f0a7206694
3 changed files with 16 additions and 33 deletions

View File

@ -4,7 +4,6 @@
extern crate rocket; extern crate rocket;
use rocket::config::{Environment, Config}; use rocket::config::{Environment, Config};
use rocket::http::RawStr;
#[get("/", format = "application/json")] #[get("/", format = "application/json")]
fn get() -> &'static str { "get" } fn get() -> &'static str { "get" }
@ -26,21 +25,7 @@ mod benches {
use self::test::Bencher; use self::test::Bencher;
use rocket::testing::MockRequest; use rocket::testing::MockRequest;
use rocket::http::Method::*; use rocket::http::Method::*;
use rocket::http::{Accept, ContentType}; use rocket::http::ContentType;
#[bench]
fn accept_format(b: &mut Bencher) {
let rocket = rocket();
let mut request = MockRequest::new(Get, "/").header(Accept::JSON);
b.iter(|| { request.dispatch_with(&rocket); });
}
#[bench]
fn wrong_accept_format(b: &mut Bencher) {
let rocket = rocket();
let mut request = MockRequest::new(Get, "/").header(Accept::HTML);
b.iter(|| { request.dispatch_with(&rocket); });
}
#[bench] #[bench]
fn content_type_format(b: &mut Bencher) { fn content_type_format(b: &mut Bencher) {

View File

@ -4,7 +4,6 @@
extern crate rocket; extern crate rocket;
use rocket::config::{Environment, Config}; use rocket::config::{Environment, Config};
use rocket::http::RawStr;
#[get("/", format = "application/json")] #[get("/", format = "application/json")]
fn get() -> &'static str { "json" } fn get() -> &'static str { "json" }
@ -39,22 +38,22 @@ mod benches {
use self::test::Bencher; use self::test::Bencher;
use rocket::testing::MockRequest; use rocket::testing::MockRequest;
use rocket::http::Method::*; use rocket::http::Method::*;
use rocket::http::{Accept, ContentType}; use rocket::http::ContentType;
#[bench] // #[bench]
fn accept_format(b: &mut Bencher) { // fn accept_format(b: &mut Bencher) {
let rocket = rocket(); // let rocket = rocket();
let mut requests = vec![]; // let mut requests = vec![];
requests.push(MockRequest::new(Get, "/").header(Accept::JSON)); // requests.push(MockRequest::new(Get, "/").header(Accept::JSON));
requests.push(MockRequest::new(Get, "/").header(Accept::HTML)); // requests.push(MockRequest::new(Get, "/").header(Accept::HTML));
requests.push(MockRequest::new(Get, "/").header(Accept::Plain)); // requests.push(MockRequest::new(Get, "/").header(Accept::Plain));
b.iter(|| { // b.iter(|| {
for request in requests.iter_mut() { // for request in requests.iter_mut() {
request.dispatch_with(&rocket); // request.dispatch_with(&rocket);
} // }
}); // });
} // }
#[bench] #[bench]
fn content_type_format(b: &mut Bencher) { fn content_type_format(b: &mut Bencher) {

View File

@ -4,7 +4,6 @@
extern crate rocket; extern crate rocket;
use rocket::config::{Environment, Config}; use rocket::config::{Environment, Config};
use rocket::http::RawStr;
#[get("/")] #[get("/")]
fn get_index() -> &'static str { "index" } fn get_index() -> &'static str { "index" }
@ -25,7 +24,7 @@ fn index_b() -> &'static str { "index" }
fn index_c() -> &'static str { "index" } fn index_c() -> &'static str { "index" }
#[get("/<a>")] #[get("/<a>")]
fn index_dyn_a(a: &RawStr) -> &'static str { "index" } fn index_dyn_a(a: &str) -> &'static str { "index" }
fn rocket() -> rocket::Rocket { fn rocket() -> rocket::Rocket {
let config = Config::new(Environment::Production).unwrap(); let config = Config::new(Environment::Production).unwrap();