mirror of https://github.com/rwf2/Rocket.git
Use 'bencher' for benchmarks on stable.
This commit is contained in:
parent
9a2149b43d
commit
cd7e99a535
|
@ -53,5 +53,18 @@ yansi = "0.5"
|
|||
version_check = "0.9.1"
|
||||
|
||||
[dev-dependencies]
|
||||
bencher = "0.1"
|
||||
# TODO: Find a way to not depend on this.
|
||||
lazy_static = "1.0"
|
||||
|
||||
[[bench]]
|
||||
name = "format-routing"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "ranked-routing"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "simple-routing"
|
||||
harness = false
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#![cfg_attr(test, feature(test))]
|
||||
#[macro_use] extern crate rocket;
|
||||
#[macro_use] extern crate bencher;
|
||||
|
||||
use rocket::local::blocking::Client;
|
||||
use rocket::config::{Environment, Config, LoggingLevel};
|
||||
|
||||
#[get("/", format = "application/json")]
|
||||
|
@ -14,44 +15,38 @@ fn rocket() -> rocket::Rocket {
|
|||
rocket::custom(config.unwrap()).mount("/", routes![get, post])
|
||||
}
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
mod benches {
|
||||
extern crate test;
|
||||
use bencher::Bencher;
|
||||
use rocket::http::{Accept, ContentType};
|
||||
|
||||
use super::rocket;
|
||||
use self::test::Bencher;
|
||||
use rocket::local::blocking::Client;
|
||||
use rocket::http::{Accept, ContentType};
|
||||
|
||||
fn client(_rocket: rocket::Rocket) -> Option<Client> {
|
||||
unimplemented!("waiting for sync-client");
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn accept_format(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn accept_format(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
let request = client.get("/").header(Accept::JSON);
|
||||
b.iter(|| { request.clone().dispatch(); });
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn wrong_accept_format(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn wrong_accept_format(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
let request = client.get("/").header(Accept::HTML);
|
||||
b.iter(|| { request.clone().dispatch(); });
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn content_type_format(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn content_type_format(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
let request = client.post("/").header(ContentType::JSON);
|
||||
b.iter(|| { request.clone().dispatch(); });
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn wrong_content_type_format(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn wrong_content_type_format(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
let request = client.post("/").header(ContentType::Plain);
|
||||
b.iter(|| { request.clone().dispatch(); });
|
||||
}
|
||||
}
|
||||
|
||||
benchmark_main!(benches);
|
||||
benchmark_group! {
|
||||
benches,
|
||||
accept_format,
|
||||
wrong_accept_format,
|
||||
content_type_format,
|
||||
wrong_content_type_format,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![cfg_attr(test, feature(test))]
|
||||
#[macro_use] extern crate rocket;
|
||||
#[macro_use] extern crate bencher;
|
||||
|
||||
use rocket::config::{Environment, Config, LoggingLevel};
|
||||
|
||||
|
@ -28,22 +28,12 @@ fn rocket() -> rocket::Rocket {
|
|||
.mount("/", routes![post, post2, post3])
|
||||
}
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
mod benches {
|
||||
extern crate test;
|
||||
use bencher::Bencher;
|
||||
use rocket::local::blocking::Client;
|
||||
use rocket::http::{Accept, ContentType};
|
||||
|
||||
use super::rocket;
|
||||
use self::test::Bencher;
|
||||
use rocket::local::blocking::Client;
|
||||
use rocket::http::{Accept, ContentType};
|
||||
|
||||
fn client(_rocket: rocket::Rocket) -> Option<Client> {
|
||||
unimplemented!("waiting for sync-client");
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn accept_format(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn accept_format(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
let requests = vec![
|
||||
client.get("/").header(Accept::JSON),
|
||||
client.get("/").header(Accept::HTML),
|
||||
|
@ -55,11 +45,10 @@ mod benches {
|
|||
request.clone().dispatch();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn content_type_format(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn content_type_format(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
let requests = vec![
|
||||
client.post("/").header(ContentType::JSON),
|
||||
client.post("/").header(ContentType::HTML),
|
||||
|
@ -71,5 +60,11 @@ mod benches {
|
|||
request.clone().dispatch();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchmark_main!(benches);
|
||||
benchmark_group! {
|
||||
benches,
|
||||
accept_format,
|
||||
content_type_format,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![cfg_attr(test, feature(test))]
|
||||
#[macro_use] extern crate rocket;
|
||||
#[macro_use] extern crate bencher;
|
||||
|
||||
use rocket::config::{Environment, Config, LoggingLevel};
|
||||
use rocket::http::RawStr;
|
||||
|
@ -40,39 +40,27 @@ fn rocket() -> rocket::Rocket {
|
|||
index_b, index_c, index_dyn_a])
|
||||
}
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
mod benches {
|
||||
extern crate test;
|
||||
use bencher::Bencher;
|
||||
use rocket::local::blocking::Client;
|
||||
|
||||
use super::{hello_world_rocket, rocket};
|
||||
use self::test::Bencher;
|
||||
use rocket::local::blocking::Client;
|
||||
|
||||
fn client(_rocket: rocket::Rocket) -> Option<Client> {
|
||||
unimplemented!("waiting for sync-client");
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_hello_world(b: &mut Bencher) {
|
||||
let client = client(hello_world_rocket()).unwrap();
|
||||
fn bench_hello_world(b: &mut Bencher) {
|
||||
let client = Client::new(hello_world_rocket()).unwrap();
|
||||
|
||||
b.iter(|| {
|
||||
client.get("/").dispatch();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_single_get_index(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn bench_single_get_index(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
|
||||
b.iter(|| {
|
||||
client.get("/").dispatch();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_get_put_post_index(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn bench_get_put_post_index(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
|
||||
// Hold all of the requests we're going to make during the benchmark.
|
||||
let mut requests = vec![];
|
||||
|
@ -85,11 +73,10 @@ mod benches {
|
|||
request.clone().dispatch();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_dynamic(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn bench_dynamic(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
|
||||
// Hold all of the requests we're going to make during the benchmark.
|
||||
let mut requests = vec![];
|
||||
|
@ -102,11 +89,10 @@ mod benches {
|
|||
request.clone().dispatch();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_simple_routing(b: &mut Bencher) {
|
||||
let client = client(rocket()).unwrap();
|
||||
fn bench_simple_routing(b: &mut Bencher) {
|
||||
let client = Client::new(rocket()).unwrap();
|
||||
|
||||
// Hold all of the requests we're going to make during the benchmark.
|
||||
let mut requests = vec![];
|
||||
|
@ -125,5 +111,14 @@ mod benches {
|
|||
request.clone().dispatch();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchmark_main!(benches);
|
||||
benchmark_group! {
|
||||
benches,
|
||||
bench_hello_world,
|
||||
bench_single_get_index,
|
||||
bench_get_put_post_index,
|
||||
bench_dynamic,
|
||||
bench_simple_routing,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue