mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-05 17:22:36 +00:00
5d9035ddc1
In brief, this commit: * Updates to the latest upstream 'cookie', fixing a memory leak. * Make changes to 'CookieJar' observable only through 'pending()'. * Deprecates 'Client::new()' in favor of 'Client::tracked()'. * Makes 'dispatch()' on tracked 'Client's synchronize on cookies. * Makes 'Client::untracked()' actually untracked. This commit updates to the latest 'cookie' which removes support for 'Sync' cookie jars. Instead of relying on 'cookie', this commit implements an op-log based 'CookieJar' which internally keeps track of changes. The API is such that changes are only observable through specialized '_pending()' methods.
125 lines
3.1 KiB
Rust
125 lines
3.1 KiB
Rust
#[macro_use] extern crate rocket;
|
|
#[macro_use] extern crate bencher;
|
|
|
|
use rocket::config::{Environment, Config, LoggingLevel};
|
|
use rocket::http::RawStr;
|
|
|
|
#[get("/")]
|
|
fn hello_world() -> &'static str { "Hello, world!" }
|
|
|
|
#[get("/")]
|
|
fn get_index() -> &'static str { "index" }
|
|
|
|
#[put("/")]
|
|
fn put_index() -> &'static str { "index" }
|
|
|
|
#[post("/")]
|
|
fn post_index() -> &'static str { "index" }
|
|
|
|
#[get("/a")]
|
|
fn index_a() -> &'static str { "index" }
|
|
|
|
#[get("/b")]
|
|
fn index_b() -> &'static str { "index" }
|
|
|
|
#[get("/c")]
|
|
fn index_c() -> &'static str { "index" }
|
|
|
|
#[get("/<_a>")]
|
|
fn index_dyn_a(_a: &RawStr) -> &'static str { "index" }
|
|
|
|
fn hello_world_rocket() -> rocket::Rocket {
|
|
let config = Config::build(Environment::Production).log_level(LoggingLevel::Off);
|
|
rocket::custom(config.unwrap()).mount("/", routes![hello_world])
|
|
}
|
|
|
|
fn rocket() -> rocket::Rocket {
|
|
let config = Config::build(Environment::Production).log_level(LoggingLevel::Off);
|
|
rocket::custom(config.unwrap())
|
|
.mount("/", routes![get_index, put_index, post_index, index_a,
|
|
index_b, index_c, index_dyn_a])
|
|
}
|
|
|
|
use bencher::Bencher;
|
|
use rocket::local::blocking::Client;
|
|
|
|
fn bench_hello_world(b: &mut Bencher) {
|
|
let client = Client::tracked(hello_world_rocket()).unwrap();
|
|
|
|
b.iter(|| {
|
|
client.get("/").dispatch();
|
|
});
|
|
}
|
|
|
|
fn bench_single_get_index(b: &mut Bencher) {
|
|
let client = Client::tracked(rocket()).unwrap();
|
|
|
|
b.iter(|| {
|
|
client.get("/").dispatch();
|
|
});
|
|
}
|
|
|
|
fn bench_get_put_post_index(b: &mut Bencher) {
|
|
let client = Client::tracked(rocket()).unwrap();
|
|
|
|
// Hold all of the requests we're going to make during the benchmark.
|
|
let mut requests = vec![];
|
|
requests.push(client.get("/"));
|
|
requests.push(client.put("/"));
|
|
requests.push(client.post("/"));
|
|
|
|
b.iter(|| {
|
|
for request in &requests {
|
|
request.clone().dispatch();
|
|
}
|
|
});
|
|
}
|
|
|
|
fn bench_dynamic(b: &mut Bencher) {
|
|
let client = Client::tracked(rocket()).unwrap();
|
|
|
|
// Hold all of the requests we're going to make during the benchmark.
|
|
let mut requests = vec![];
|
|
requests.push(client.get("/abc"));
|
|
requests.push(client.get("/abcdefg"));
|
|
requests.push(client.get("/123"));
|
|
|
|
b.iter(|| {
|
|
for request in &requests {
|
|
request.clone().dispatch();
|
|
}
|
|
});
|
|
}
|
|
|
|
fn bench_simple_routing(b: &mut Bencher) {
|
|
let client = Client::tracked(rocket()).unwrap();
|
|
|
|
// Hold all of the requests we're going to make during the benchmark.
|
|
let mut requests = vec![];
|
|
for route in client.cargo().routes() {
|
|
let request = client.req(route.method, route.uri.path());
|
|
requests.push(request);
|
|
}
|
|
|
|
// A few more for the dynamic route.
|
|
requests.push(client.get("/abc"));
|
|
requests.push(client.get("/abcdefg"));
|
|
requests.push(client.get("/123"));
|
|
|
|
b.iter(|| {
|
|
for request in &requests {
|
|
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,
|
|
}
|