Skip to content

Commit

Permalink
Added benchmarks for parsing Method (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ien authored Jan 25, 2021
1 parent 7ba575f commit 5b90e38
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ path = "benches/header_name.rs"
name = "header_value"
path = "benches/header_value.rs"

[[bench]]
name = "method"
path = "benches/method.rs"

[[bench]]
name = "uri"
path = "benches/uri.rs"
40 changes: 40 additions & 0 deletions benches/method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#![feature(test)]

extern crate test;

use http::method::Method;
use test::Bencher;

fn make_all_methods() -> Vec<Vec<u8>> {
vec![
b"OPTIONS".to_vec(),
b"GET".to_vec(),
b"POST".to_vec(),
b"PUT".to_vec(),
b"DELETE".to_vec(),
b"HEAD".to_vec(),
b"TRACE".to_vec(),
b"CONNECT".to_vec(),
b"PATCH".to_vec(),
b"CUSTOM_SHORT".to_vec(),
b"CUSTOM_LONG_METHOD".to_vec(),
]
}

#[bench]
fn method_easy(b: &mut Bencher) {
let name = b"GET";
b.iter(|| {
Method::from_bytes(&name[..]).unwrap();
});
}

#[bench]
fn method_various(b: &mut Bencher) {
let all_methods = make_all_methods();
b.iter(|| {
for name in &all_methods {
Method::from_bytes(name.as_slice()).unwrap();
}
});
}

0 comments on commit 5b90e38

Please sign in to comment.