summaryrefslogtreecommitdiffstats
path: root/third_party/rust/http/benches/header_value.rs
blob: 2e1004e96ef1767796957fe197e4d4da64f94ffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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());
    });
}