summaryrefslogtreecommitdiffstats
path: root/third_party/rust/http/benches
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/http/benches')
-rw-r--r--third_party/rust/http/benches/header_map/basic.rs595
-rw-r--r--third_party/rust/http/benches/header_map/mod.rs6
-rw-r--r--third_party/rust/http/benches/header_map/vec_map.rs107
-rw-r--r--third_party/rust/http/benches/header_name.rs296
-rw-r--r--third_party/rust/http/benches/header_name2.rs52
-rw-r--r--third_party/rust/http/benches/header_value.rs46
-rw-r--r--third_party/rust/http/benches/method.rs40
-rw-r--r--third_party/rust/http/benches/uri.rs32
8 files changed, 1174 insertions, 0 deletions
diff --git a/third_party/rust/http/benches/header_map/basic.rs b/third_party/rust/http/benches/header_map/basic.rs
new file mode 100644
index 0000000000..078b89fb4c
--- /dev/null
+++ b/third_party/rust/http/benches/header_map/basic.rs
@@ -0,0 +1,595 @@
+macro_rules! bench {
+ ($name:ident($map:ident, $b:ident) $body:expr) => {
+ mod $name {
+ #[allow(unused_imports)]
+ use super::custom_hdr;
+ use fnv::FnvHasher;
+ use http::header::*;
+ use seahash::SeaHasher;
+ use std::hash::BuildHasherDefault;
+ #[allow(unused_imports)]
+ use test::{self, Bencher};
+
+ #[bench]
+ fn header_map($b: &mut Bencher) {
+ let $map = || HeaderMap::default();
+ $body
+ }
+
+ #[bench]
+ fn order_map_fnv($b: &mut Bencher) {
+ use indexmap::IndexMap;
+ let $map = || IndexMap::<_, _, BuildHasherDefault<FnvHasher>>::default();
+ $body
+ }
+
+ #[bench]
+ fn vec_map($b: &mut Bencher) {
+ use crate::vec_map::VecMap;
+
+ let $map = || VecMap::with_capacity(0);
+ $body
+ }
+
+ #[bench]
+ fn order_map_seahash($b: &mut Bencher) {
+ use indexmap::IndexMap;
+ let $map = || IndexMap::<_, _, BuildHasherDefault<SeaHasher>>::default();
+ $body
+ }
+
+ /*
+ #[bench]
+ fn order_map_siphash($b: &mut Bencher) {
+ use indexmap::IndexMap;
+ let $map = || IndexMap::new();
+ $body
+ }
+
+ #[bench]
+ fn std_map_siphash($b: &mut Bencher) {
+ use std::collections::HashMap;
+ let $map = || HashMap::new();
+ $body
+ }
+ */
+ }
+ };
+}
+
+bench!(new_insert_get_host(new_map, b) {
+ b.iter(|| {
+ let mut h = new_map();
+ h.insert(HOST, "hyper.rs");
+ test::black_box(h.get(&HOST));
+ })
+});
+
+bench!(insert_4_std_get_30(new_map, b) {
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for i in 0..4 {
+ h.insert(super::STD[i].clone(), "foo");
+ }
+
+ for i in 0..30 {
+ test::black_box(h.get(&super::STD[i % 4]));
+ }
+ })
+});
+
+bench!(insert_6_std_get_6(new_map, b) {
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for i in 0..6 {
+ h.insert(super::STD[i].clone(), "foo");
+ }
+
+ for i in 0..6 {
+ test::black_box(h.get(&super::STD[i % 4]));
+ }
+ })
+});
+
+/*
+bench!(insert_remove_host(new_map, b) {
+ let mut h = new_map();
+
+ b.iter(|| {
+ test::black_box(h.insert(HOST, "hyper.rs"));
+ test::black_box(h.remove(&HOST));
+ })
+});
+
+bench!(insert_insert_host(new_map, b) {
+ let mut h = new_map();
+
+ b.iter(|| {
+ test::black_box(h.insert(HOST, "hyper.rs"));
+ test::black_box(h.insert(HOST, "hyper.rs"));
+ })
+});
+*/
+
+bench!(get_10_of_20_std(new_map, b) {
+ let mut h = new_map();
+
+ for hdr in super::STD[10..30].iter() {
+ h.insert(hdr.clone(), hdr.as_str().to_string());
+ }
+
+ b.iter(|| {
+ for hdr in &super::STD[10..20] {
+ test::black_box(h.get(hdr));
+ }
+ })
+});
+
+bench!(get_100_std(new_map, b) {
+ let mut h = new_map();
+
+ for hdr in super::STD.iter() {
+ h.insert(hdr.clone(), hdr.as_str().to_string());
+ }
+
+ b.iter(|| {
+ for i in 0..100 {
+ test::black_box(h.get(&super::STD[i % super::STD.len()]));
+ }
+ })
+});
+
+bench!(set_8_get_1_std(new_map, b) {
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &super::STD[0..8] {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&super::STD[0]));
+ })
+});
+
+bench!(set_10_get_1_std(new_map, b) {
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &super::STD[0..10] {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&super::STD[0]));
+ })
+});
+
+bench!(set_20_get_1_std(new_map, b) {
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &super::STD[0..20] {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&super::STD[0]));
+ })
+});
+
+bench!(get_10_custom_short(new_map, b) {
+ let hdrs = custom_hdr(20);
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), hdr.as_str().to_string());
+ }
+
+ b.iter(|| {
+ for hdr in &hdrs[..10] {
+ test::black_box(h.get(hdr));
+ }
+ })
+});
+
+bench!(set_10_get_1_custom_short(new_map, b) {
+ let hdrs = custom_hdr(10);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&hdrs[0]));
+ })
+});
+
+bench!(set_10_get_1_custom_med(new_map, b) {
+ let hdrs = super::med_custom_hdr(10);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&hdrs[0]));
+ })
+});
+
+bench!(set_10_get_1_custom_long(new_map, b) {
+ let hdrs = super::long_custom_hdr(10);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&hdrs[0]));
+ })
+});
+
+bench!(set_10_get_1_custom_very_long(new_map, b) {
+ let hdrs = super::very_long_custom_hdr(10);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&hdrs[0]));
+ })
+});
+
+bench!(set_20_get_1_custom_short(new_map, b) {
+ let hdrs = custom_hdr(20);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&hdrs[0]));
+ })
+});
+
+bench!(set_20_get_1_custom_med(new_map, b) {
+ let hdrs = super::med_custom_hdr(20);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&hdrs[0]));
+ })
+});
+
+bench!(set_20_get_1_custom_long(new_map, b) {
+ let hdrs = super::long_custom_hdr(20);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&hdrs[0]));
+ })
+});
+
+bench!(set_20_get_1_custom_very_long(new_map, b) {
+ let hdrs = super::very_long_custom_hdr(20);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+
+ test::black_box(h.get(&hdrs[0]));
+ })
+});
+
+bench!(insert_all_std_headers(new_map, b) {
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in super::STD {
+ test::black_box(h.insert(hdr.clone(), "foo"));
+ }
+ })
+});
+
+bench!(insert_79_custom_std_headers(new_map, b) {
+ let hdrs = super::custom_std(79);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ h.insert(hdr.clone(), "foo");
+ }
+ })
+});
+
+bench!(insert_100_custom_headers(new_map, b) {
+ let hdrs = custom_hdr(100);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ test::black_box(h.insert(hdr.clone(), "foo"));
+ }
+ })
+});
+
+bench!(insert_500_custom_headers(new_map, b) {
+ let hdrs = custom_hdr(500);
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for hdr in &hdrs {
+ test::black_box(h.insert(hdr.clone(), "foo"));
+ }
+ })
+});
+
+bench!(insert_one_15_char_header(new_map, b) {
+ let hdr: HeaderName = "abcd-abcd-abcde"
+ .parse().unwrap();
+
+ b.iter(|| {
+ let mut h = new_map();
+ h.insert(hdr.clone(), "hello");
+ test::black_box(h);
+ })
+});
+
+bench!(insert_one_25_char_header(new_map, b) {
+ let hdr: HeaderName = "abcd-abcd-abcd-abcd-abcde"
+ .parse().unwrap();
+
+ b.iter(|| {
+ let mut h = new_map();
+ h.insert(hdr.clone(), "hello");
+ test::black_box(h);
+ })
+});
+
+bench!(insert_one_50_char_header(new_map, b) {
+ let hdr: HeaderName = "abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcde"
+ .parse().unwrap();
+
+ b.iter(|| {
+ let mut h = new_map();
+ h.insert(hdr.clone(), "hello");
+ test::black_box(h);
+ })
+});
+
+bench!(insert_one_100_char_header(new_map, b) {
+ let hdr: HeaderName = "abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcdeabcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcde"
+ .parse().unwrap();
+
+ b.iter(|| {
+ let mut h = new_map();
+ h.insert(hdr.clone(), "hello");
+ test::black_box(h);
+ })
+});
+
+const HN_HDRS: [(&'static str, &'static str); 11] = [
+ ("Date", "Fri, 27 Jan 2017 23:00:00 GMT"),
+ ("Content-Type", "text/html; charset=utf-8"),
+ ("Transfer-Encoding", "chunked"),
+ ("Connection", "keep-alive"),
+ ("Set-Cookie", "__cfduid=dbdfbbe3822b61cb8750ba37d894022151485558000; expires=Sat, 27-Jan-18 23:00:00 GMT; path=/; domain=.ycombinator.com; HttpOnly"),
+ ("Vary", "Accept-Encoding"),
+ ("Cache-Control", "private"),
+ ("X-Frame-Options", "DENY"),
+ ("Strict-Transport-Security", "max-age=31556900; includeSubDomains"),
+ ("Server", "cloudflare-nginx"),
+ ("CF-RAY", "327fd1809f3c1baf-SEA"),
+];
+
+bench!(hn_hdrs_set_8_get_many(new_map, b) {
+ let hdrs: Vec<(HeaderName, &'static str)> = super::HN_HDRS[..8].iter()
+ .map(|&(name, val)| (name.parse().unwrap(), val))
+ .collect();
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for &(ref name, val) in hdrs.iter() {
+ h.insert(name.clone(), val);
+ }
+
+ for _ in 0..15 {
+ test::black_box(h.get(&CONTENT_LENGTH));
+ test::black_box(h.get(&VARY));
+ }
+ });
+});
+
+bench!(hn_hdrs_set_8_get_miss(new_map, b) {
+ let hdrs: Vec<(HeaderName, &'static str)> = super::HN_HDRS[..8].iter()
+ .map(|&(name, val)| (name.parse().unwrap(), val))
+ .collect();
+
+ let miss: HeaderName = "x-wat".parse().unwrap();
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for &(ref name, val) in hdrs.iter() {
+ h.insert(name.clone(), val);
+ }
+
+ test::black_box(h.get(&CONTENT_LENGTH));
+ test::black_box(h.get(&miss));
+ });
+});
+
+bench!(hn_hdrs_set_11_get_with_miss(new_map, b) {
+ let hdrs: Vec<(HeaderName, &'static str)> = super::HN_HDRS.iter()
+ .map(|&(name, val)| (name.parse().unwrap(), val))
+ .collect();
+
+ let miss: HeaderName = "x-wat".parse().unwrap();
+
+ b.iter(|| {
+ let mut h = new_map();
+
+ for &(ref name, val) in hdrs.iter() {
+ h.insert(name.clone(), val);
+ }
+
+ for _ in 0..10 {
+ test::black_box(h.get(&CONTENT_LENGTH));
+ test::black_box(h.get(&VARY));
+ test::black_box(h.get(&miss));
+ }
+ });
+});
+
+use http::header::*;
+
+fn custom_hdr(n: usize) -> Vec<HeaderName> {
+ (0..n)
+ .map(|i| {
+ let s = format!("x-custom-{}", i);
+ s.parse().unwrap()
+ })
+ .collect()
+}
+
+fn med_custom_hdr(n: usize) -> Vec<HeaderName> {
+ (0..n)
+ .map(|i| {
+ let s = format!("content-length-{}", i);
+ s.parse().unwrap()
+ })
+ .collect()
+}
+
+fn long_custom_hdr(n: usize) -> Vec<HeaderName> {
+ (0..n)
+ .map(|i| {
+ let s = format!("access-control-allow-headers-{}", i);
+ s.parse().unwrap()
+ })
+ .collect()
+}
+
+fn very_long_custom_hdr(n: usize) -> Vec<HeaderName> {
+ (0..n)
+ .map(|i| {
+ let s = format!("access-control-allow-access-control-allow-headers-{}", i);
+ s.parse().unwrap()
+ })
+ .collect()
+}
+
+fn custom_std(n: usize) -> Vec<HeaderName> {
+ (0..n)
+ .map(|i| {
+ let s = format!("{}-{}", STD[i % STD.len()].as_str(), i);
+ s.parse().unwrap()
+ })
+ .collect()
+}
+
+const STD: &'static [HeaderName] = &[
+ ACCEPT,
+ ACCEPT_CHARSET,
+ ACCEPT_ENCODING,
+ ACCEPT_LANGUAGE,
+ ACCEPT_RANGES,
+ ACCESS_CONTROL_ALLOW_CREDENTIALS,
+ ACCESS_CONTROL_ALLOW_HEADERS,
+ ACCESS_CONTROL_ALLOW_METHODS,
+ ACCESS_CONTROL_ALLOW_ORIGIN,
+ ACCESS_CONTROL_EXPOSE_HEADERS,
+ ACCESS_CONTROL_MAX_AGE,
+ ACCESS_CONTROL_REQUEST_HEADERS,
+ ACCESS_CONTROL_REQUEST_METHOD,
+ AGE,
+ ALLOW,
+ ALT_SVC,
+ AUTHORIZATION,
+ CACHE_CONTROL,
+ CONNECTION,
+ CONTENT_DISPOSITION,
+ CONTENT_ENCODING,
+ CONTENT_LANGUAGE,
+ CONTENT_LENGTH,
+ CONTENT_LOCATION,
+ CONTENT_RANGE,
+ CONTENT_SECURITY_POLICY,
+ CONTENT_SECURITY_POLICY_REPORT_ONLY,
+ CONTENT_TYPE,
+ COOKIE,
+ DNT,
+ DATE,
+ ETAG,
+ EXPECT,
+ EXPIRES,
+ FORWARDED,
+ FROM,
+ HOST,
+ IF_MATCH,
+ IF_MODIFIED_SINCE,
+ IF_NONE_MATCH,
+ IF_RANGE,
+ IF_UNMODIFIED_SINCE,
+ LAST_MODIFIED,
+ LINK,
+ LOCATION,
+ MAX_FORWARDS,
+ ORIGIN,
+ PRAGMA,
+ PROXY_AUTHENTICATE,
+ PROXY_AUTHORIZATION,
+ PUBLIC_KEY_PINS,
+ PUBLIC_KEY_PINS_REPORT_ONLY,
+ RANGE,
+ REFERER,
+ REFERRER_POLICY,
+ REFRESH,
+ RETRY_AFTER,
+ SERVER,
+ SET_COOKIE,
+ STRICT_TRANSPORT_SECURITY,
+ TE,
+ TRAILER,
+ TRANSFER_ENCODING,
+ USER_AGENT,
+ UPGRADE,
+ UPGRADE_INSECURE_REQUESTS,
+ VARY,
+ VIA,
+ WARNING,
+ WWW_AUTHENTICATE,
+ X_CONTENT_TYPE_OPTIONS,
+ X_DNS_PREFETCH_CONTROL,
+ X_FRAME_OPTIONS,
+ X_XSS_PROTECTION,
+];
diff --git a/third_party/rust/http/benches/header_map/mod.rs b/third_party/rust/http/benches/header_map/mod.rs
new file mode 100644
index 0000000000..d0317b333a
--- /dev/null
+++ b/third_party/rust/http/benches/header_map/mod.rs
@@ -0,0 +1,6 @@
+#![feature(test)]
+
+extern crate test;
+
+mod basic;
+mod vec_map;
diff --git a/third_party/rust/http/benches/header_map/vec_map.rs b/third_party/rust/http/benches/header_map/vec_map.rs
new file mode 100644
index 0000000000..1a3eb15d1a
--- /dev/null
+++ b/third_party/rust/http/benches/header_map/vec_map.rs
@@ -0,0 +1,107 @@
+#![allow(dead_code)]
+
+#[derive(Clone)]
+pub struct VecMap<K, V> {
+ vec: Vec<(K, V)>,
+}
+
+impl<K: PartialEq, V> VecMap<K, V> {
+ #[inline]
+ pub fn with_capacity(cap: usize) -> VecMap<K, V> {
+ VecMap {
+ vec: Vec::with_capacity(cap),
+ }
+ }
+
+ #[inline]
+ pub fn insert(&mut self, key: K, value: V) {
+ match self.find(&key) {
+ Some(pos) => self.vec[pos] = (key, value),
+ None => self.vec.push((key, value)),
+ }
+ }
+
+ #[inline]
+ pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
+ match self.find(&key) {
+ Some(pos) => Entry::Occupied(OccupiedEntry {
+ vec: self,
+ pos: pos,
+ }),
+ None => Entry::Vacant(VacantEntry {
+ vec: self,
+ key: key,
+ }),
+ }
+ }
+
+ #[inline]
+ pub fn get<K2: PartialEq<K> + ?Sized>(&self, key: &K2) -> Option<&V> {
+ self.find(key).map(move |pos| &self.vec[pos].1)
+ }
+
+ #[inline]
+ pub fn get_mut<K2: PartialEq<K> + ?Sized>(&mut self, key: &K2) -> Option<&mut V> {
+ self.find(key).map(move |pos| &mut self.vec[pos].1)
+ }
+
+ #[inline]
+ pub fn contains_key<K2: PartialEq<K> + ?Sized>(&self, key: &K2) -> bool {
+ self.find(key).is_some()
+ }
+
+ #[inline]
+ pub fn len(&self) -> usize {
+ self.vec.len()
+ }
+
+ #[inline]
+ pub fn iter(&self) -> ::std::slice::Iter<'_, (K, V)> {
+ self.vec.iter()
+ }
+ #[inline]
+ pub fn remove<K2: PartialEq<K> + ?Sized>(&mut self, key: &K2) -> Option<V> {
+ self.find(key)
+ .map(|pos| self.vec.remove(pos))
+ .map(|(_, v)| v)
+ }
+ #[inline]
+ pub fn clear(&mut self) {
+ self.vec.clear();
+ }
+
+ #[inline]
+ fn find<K2: PartialEq<K> + ?Sized>(&self, key: &K2) -> Option<usize> {
+ self.vec.iter().position(|entry| key == &entry.0)
+ }
+}
+
+pub enum Entry<'a, K: 'a, V: 'a> {
+ Vacant(VacantEntry<'a, K, V>),
+ Occupied(OccupiedEntry<'a, K, V>),
+}
+
+pub struct VacantEntry<'a, K, V> {
+ vec: &'a mut VecMap<K, V>,
+ key: K,
+}
+
+impl<'a, K, V> VacantEntry<'a, K, V> {
+ pub fn insert(self, val: V) -> &'a mut V {
+ let vec = self.vec;
+ vec.vec.push((self.key, val));
+ let pos = vec.vec.len() - 1;
+ &mut vec.vec[pos].1
+ }
+}
+
+pub struct OccupiedEntry<'a, K, V> {
+ vec: &'a mut VecMap<K, V>,
+ pos: usize,
+}
+
+impl<'a, K, V> OccupiedEntry<'a, K, V> {
+ pub fn into_mut(self) -> &'a mut V {
+ &mut self.vec.vec[self.pos].1
+ }
+}
diff --git a/third_party/rust/http/benches/header_name.rs b/third_party/rust/http/benches/header_name.rs
new file mode 100644
index 0000000000..4249f98778
--- /dev/null
+++ b/third_party/rust/http/benches/header_name.rs
@@ -0,0 +1,296 @@
+#![feature(test)]
+
+extern crate bytes;
+extern crate http;
+extern crate test;
+
+use http::header::HeaderName;
+use test::Bencher;
+
+fn make_all_known_headers() -> Vec<Vec<u8>> {
+ // Standard request headers
+ vec![b"A-IM".to_vec(),
+ b"Accept".to_vec(),
+ b"Accept-Charset".to_vec(),
+ b"Accept-Datetime".to_vec(),
+ b"Accept-Encoding".to_vec(),
+ b"Accept-Language".to_vec(),
+ b"Access-Control-Request-Method".to_vec(),
+ b"Authorization".to_vec(),
+ b"Cache-Control".to_vec(),
+ b"Connection".to_vec(),
+ b"Permanent".to_vec(),
+ b"Content-Length".to_vec(),
+ b"Content-MD5".to_vec(),
+ b"Content-Type".to_vec(),
+ b"Cookie".to_vec(),
+ b"Date".to_vec(),
+ b"Expect".to_vec(),
+ b"Forwarded".to_vec(),
+ b"From".to_vec(),
+ b"Host".to_vec(),
+ b"Permanent".to_vec(),
+ b"HTTP2-Settings".to_vec(),
+ b"If-Match".to_vec(),
+ b"If-Modified-Since".to_vec(),
+ b"If-None-Match".to_vec(),
+ b"If-Range".to_vec(),
+ b"If-Unmodified-Since".to_vec(),
+ b"Max-Forwards".to_vec(),
+ b"Origin".to_vec(),
+ b"Pragma".to_vec(),
+ b"Proxy-Authorization".to_vec(),
+ b"Range".to_vec(),
+ b"Referer".to_vec(),
+ b"TE".to_vec(),
+ b"User-Agent".to_vec(),
+ b"Upgrade".to_vec(),
+ b"Via".to_vec(),
+ b"Warning".to_vec(),
+ // common_non_standard
+ b"Upgrade-Insecure-Requests".to_vec(),
+ b"Upgrade-Insecure-Requests".to_vec(),
+ b"X-Requested-With".to_vec(),
+ b"DNT".to_vec(),
+ b"X-Forwarded-For".to_vec(),
+ b"X-Forwarded-Host".to_vec(),
+ b"X-Forwarded-Proto".to_vec(),
+ b"Front-End-Https".to_vec(),
+ b"X-Http-Method-Override".to_vec(),
+ b"X-ATT-DeviceId".to_vec(),
+ b"X-Wap-Profile".to_vec(),
+ b"Proxy-Connection".to_vec(),
+ b"X-UIDH".to_vec(),
+ b"X-Csrf-Token".to_vec(),
+ b"X-Request-ID".to_vec(),
+ b"X-Correlation-ID".to_vec(),
+ b"Save-Data".to_vec(),
+ // standard_response_headers
+ b"Accept-Patch".to_vec(),
+ b"Accept-Ranges".to_vec(),
+ b"Access-Control-Allow-Credentials".to_vec(),
+ b"Access-Control-Allow-Headers".to_vec(),
+ b"Access-Control-Allow-Methods".to_vec(),
+ b"Access-Control-Allow-Origin".to_vec(),
+ b"Access-Control-Expose-Headers".to_vec(),
+ b"Access-Control-Max-Age".to_vec(),
+ b"Age".to_vec(),
+ b"Allow".to_vec(),
+ b"Alt-Svc".to_vec(),
+ b"Cache-Control".to_vec(),
+ b"Connection".to_vec(),
+ b"Content-Disposition".to_vec(),
+ b"Content-Encoding".to_vec(),
+ b"Content-Language".to_vec(),
+ b"Content-Length".to_vec(),
+ b"Content-Location".to_vec(),
+ b"Content-MD5".to_vec(),
+ b"Content-Range".to_vec(),
+ b"Content-Type".to_vec(),
+ b"Date".to_vec(),
+ b"Delta-Base".to_vec(),
+ b"ETag".to_vec(),
+ b"Expires".to_vec(),
+ b"IM".to_vec(),
+ b"Last-Modified".to_vec(),
+ b"Link".to_vec(),
+ b"Location".to_vec(),
+ b"P3P".to_vec(),
+ b"Permanent".to_vec(),
+ b"Pragma".to_vec(),
+ b"Proxy-Authenticate".to_vec(),
+ b"Public-Key-Pins".to_vec(),
+ b"Retry-After".to_vec(),
+ b"Server".to_vec(),
+ b"Set-Cookie".to_vec(),
+ b"Strict-Transport-Security".to_vec(),
+ b"Tk".to_vec(),
+ b"Trailer".to_vec(),
+ b"Transfer-Encoding".to_vec(),
+ b"Upgrade".to_vec(),
+ b"Vary".to_vec(),
+ b"Via".to_vec(),
+ b"Warning".to_vec(),
+ b"WWW-Authenticate".to_vec(),
+ b"X-Frame-Options".to_vec(),
+ // common_non_standard_response
+ b"Content-Security-Policy".to_vec(),
+ b"Refresh".to_vec(),
+ b"Status".to_vec(),
+ b"Timing-Allow-Origin".to_vec(),
+ b"X-Content-Duration".to_vec(),
+ b"X-Content-Security-Policy".to_vec(),
+ b"X-Content-Type-Options".to_vec(),
+ b"X-Correlation-ID".to_vec(),
+ b"X-Powered-By".to_vec(),
+ b"X-Request-ID".to_vec(),
+ b"X-UA-Compatible".to_vec(),
+ b"X-WebKit-CSP".to_vec(),
+ b"X-XSS-Protection".to_vec(),
+ ]
+}
+
+static ALL_KNOWN_HEADERS: &[&str] = &[
+ // Standard request headers
+ "a-im",
+ "accept",
+ "accept-charset",
+ "accept-datetime",
+ "accept-encoding",
+ "accept-language",
+ "access-control-request-method",
+ "authorization",
+ "cache-control",
+ "connection",
+ "permanent",
+ "content-length",
+ "content-md5",
+ "content-type",
+ "cookie",
+ "date",
+ "expect",
+ "forwarded",
+ "from",
+ "host",
+ "permanent",
+ "http2-settings",
+ "if-match",
+ "if-modified-since",
+ "if-none-match",
+ "if-range",
+ "if-unmodified-since",
+ "max-forwards",
+ "origin",
+ "pragma",
+ "proxy-authorization",
+ "range",
+ "referer",
+ "te",
+ "user-agent",
+ "upgrade",
+ "via",
+ "warning",
+ // common_non_standard
+ "upgrade-insecure-requests",
+ "upgrade-insecure-requests",
+ "x-requested-with",
+ "dnt",
+ "x-forwarded-for",
+ "x-forwarded-host",
+ "x-forwarded-proto",
+ "front-end-https",
+ "x-http-method-override",
+ "x-att-deviceid",
+ "x-wap-profile",
+ "proxy-connection",
+ "x-uidh",
+ "x-csrf-token",
+ "x-request-id",
+ "x-correlation-id",
+ "save-data",
+ // standard_response_headers
+ "accept-patch",
+ "accept-ranges",
+ "access-control-allow-credentials",
+ "access-control-allow-headers",
+ "access-control-allow-methods",
+ "access-control-allow-origin",
+ "access-control-expose-headers",
+ "access-control-max-age",
+ "age",
+ "allow",
+ "alt-svc",
+ "cache-control",
+ "connection",
+ "content-disposition",
+ "content-encoding",
+ "content-language",
+ "content-length",
+ "content-location",
+ "content-md5",
+ "content-range",
+ "content-type",
+ "date",
+ "delta-base",
+ "etag",
+ "expires",
+ "im",
+ "last-modified",
+ "link",
+ "location",
+ "p3p",
+ "permanent",
+ "pragma",
+ "proxy-authenticate",
+ "public-key-pins",
+ "retry-after",
+ "server",
+ "set-cookie",
+ "strict-transport-security",
+ "tk",
+ "trailer",
+ "transfer-encoding",
+ "upgrade",
+ "vary",
+ "via",
+ "warning",
+ "www-authenticate",
+ "x-frame-options",
+ // common_non_standard_response
+ "content-security-policy",
+ "refresh",
+ "status",
+ "timing-allow-origin",
+ "x-content-duration",
+ "x-content-security-policy",
+ "x-content-type-options",
+ "x-correlation-id",
+ "x-powered-by",
+ "x-request-id",
+ "x-ua-compatible",
+ "x-webkit-csp",
+ "x-xss-protection",
+];
+
+#[bench]
+fn header_name_easy(b: &mut Bencher) {
+ let name = b"Content-type";
+ b.iter(|| {
+ HeaderName::from_bytes(&name[..]).unwrap();
+ });
+}
+
+#[bench]
+fn header_name_custom(b: &mut Bencher) {
+ let name = b"Foo-Bar-Baz-Blah";
+ b.iter(|| {
+ HeaderName::from_bytes(&name[..]).unwrap();
+ });
+}
+
+#[bench]
+fn header_name_bad(b: &mut Bencher) {
+ let name = b"bad header name";
+ b.iter(|| {
+ HeaderName::from_bytes(&name[..]).expect_err("Bad header name");
+ });
+}
+
+#[bench]
+fn header_name_various(b: &mut Bencher) {
+ let all_known_headers = make_all_known_headers();
+ b.iter(|| {
+ for name in &all_known_headers{
+ HeaderName::from_bytes(name.as_slice()).unwrap();
+ }
+ });
+}
+
+#[bench]
+fn header_name_from_static(b: &mut Bencher) {
+ b.iter(|| {
+ for name in ALL_KNOWN_HEADERS {
+ HeaderName::from_static(name);
+ }
+ });
+}
diff --git a/third_party/rust/http/benches/header_name2.rs b/third_party/rust/http/benches/header_name2.rs
new file mode 100644
index 0000000000..4562fd6633
--- /dev/null
+++ b/third_party/rust/http/benches/header_name2.rs
@@ -0,0 +1,52 @@
+use criterion::{criterion_group, criterion_main, BenchmarkId,Criterion, Throughput};
+use http::header::HeaderName;
+
+// This is a list of some of the standard headers ordered by increasing size.
+// It has exactly one standard header per size (some sizes don't have a standard
+// header).
+const STANDARD_HEADERS_BY_SIZE: &[&str] = &[
+ "te",
+ "age",
+ "date",
+ "allow",
+ "accept",
+ "alt-svc",
+ "if-match",
+ "forwarded",
+ "connection",
+ "retry-after",
+ "content-type",
+ "accept-ranges",
+ "accept-charset",
+ "accept-encoding",
+ "content-encoding",
+ "if-modified-since",
+ "proxy-authenticate",
+ "content-disposition",
+ "sec-websocket-accept",
+ "sec-websocket-version",
+ "access-control-max-age",
+ "content-security-policy",
+ "sec-websocket-extensions",
+ "strict-transport-security",
+ "access-control-allow-origin",
+ "access-control-allow-headers",
+ "access-control-expose-headers",
+ "access-control-request-headers",
+ "access-control-allow-credentials",
+ "content-security-policy-report-only",
+];
+
+fn header_name_by_size(c: &mut Criterion) {
+ let mut group = c.benchmark_group("std_hdr");
+ for name in STANDARD_HEADERS_BY_SIZE {
+ group.throughput(Throughput::Bytes(name.len() as u64));
+ group.bench_with_input(BenchmarkId::from_parameter(name), name, |b, name| {
+ b.iter(|| HeaderName::from_static(name) );
+ });
+ }
+ group.finish();
+}
+
+criterion_group!(benches, header_name_by_size);
+criterion_main!(benches);
diff --git a/third_party/rust/http/benches/header_value.rs b/third_party/rust/http/benches/header_value.rs
new file mode 100644
index 0000000000..2e1004e96e
--- /dev/null
+++ b/third_party/rust/http/benches/header_value.rs
@@ -0,0 +1,46 @@
+#![feature(test)]
+
+extern crate test;
+
+use bytes::Bytes;
+use http::HeaderValue;
+use test::Bencher;
+
+static SHORT: &'static [u8] = b"localhost";
+static LONG: &'static [u8] = b"Mozilla/5.0 (X11; CrOS x86_64 9592.71.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.80 Safari/537.36";
+
+#[bench]
+fn from_shared_short(b: &mut Bencher) {
+ b.bytes = SHORT.len() as u64;
+ let bytes = Bytes::from_static(SHORT);
+ b.iter(|| {
+ HeaderValue::from_maybe_shared(bytes.clone()).unwrap();
+ });
+}
+
+#[bench]
+fn from_shared_long(b: &mut Bencher) {
+ b.bytes = LONG.len() as u64;
+ let bytes = Bytes::from_static(LONG);
+ b.iter(|| {
+ HeaderValue::from_maybe_shared(bytes.clone()).unwrap();
+ });
+}
+
+#[bench]
+fn from_shared_unchecked_short(b: &mut Bencher) {
+ b.bytes = SHORT.len() as u64;
+ let bytes = Bytes::from_static(SHORT);
+ b.iter(|| unsafe {
+ HeaderValue::from_maybe_shared_unchecked(bytes.clone());
+ });
+}
+
+#[bench]
+fn from_shared_unchecked_long(b: &mut Bencher) {
+ b.bytes = LONG.len() as u64;
+ let bytes = Bytes::from_static(LONG);
+ b.iter(|| unsafe {
+ HeaderValue::from_maybe_shared_unchecked(bytes.clone());
+ });
+}
diff --git a/third_party/rust/http/benches/method.rs b/third_party/rust/http/benches/method.rs
new file mode 100644
index 0000000000..ece9b77ff6
--- /dev/null
+++ b/third_party/rust/http/benches/method.rs
@@ -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();
+ }
+ });
+}
diff --git a/third_party/rust/http/benches/uri.rs b/third_party/rust/http/benches/uri.rs
new file mode 100644
index 0000000000..031c08df2b
--- /dev/null
+++ b/third_party/rust/http/benches/uri.rs
@@ -0,0 +1,32 @@
+#![feature(test)]
+
+extern crate test;
+
+use http::Uri;
+use test::Bencher;
+
+#[bench]
+fn uri_parse_slash(b: &mut Bencher) {
+ b.bytes = 1;
+ b.iter(|| {
+ "/".parse::<Uri>().unwrap();
+ });
+}
+
+#[bench]
+fn uri_parse_relative_medium(b: &mut Bencher) {
+ let s = "/wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg";
+ b.bytes = s.len() as u64;
+ b.iter(|| {
+ s.parse::<Uri>().unwrap();
+ });
+}
+
+#[bench]
+fn uri_parse_relative_query(b: &mut Bencher) {
+ let s = "/wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg?foo={bar}|baz%13%11quux";
+ b.bytes = s.len() as u64;
+ b.iter(|| {
+ s.parse::<Uri>().unwrap();
+ });
+}