summaryrefslogtreecommitdiffstats
path: root/third_party/rust/http/benches/header_value.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/http/benches/header_value.rs')
-rw-r--r--third_party/rust/http/benches/header_value.rs46
1 files changed, 46 insertions, 0 deletions
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());
+ });
+}