pub struct StaticHead { /* private fields */ }Expand description
A response serialized once, with a Date slot patched at most once a second: the fast path
for fixed replies. The body (possibly empty) follows the head in the same buffer, so the
whole reply is one slice.
Implementations§
Source§impl StaticHead
impl StaticHead
Sourcepub fn new(
status: u16,
headers: &[(&[u8], &[u8])],
body: &[u8],
) -> Result<Self, Error>
pub fn new( status: u16, headers: &[(&[u8], &[u8])], body: &[u8], ) -> Result<Self, Error>
Serializes status, headers, Content-Length: body.len(), a Date slot and the body.
Examples found in repository?
examples/bench_parse.rs (line 96)
60fn main() {
61 let twenty = twenty_headers();
62 let cases: [(&str, &[u8]); 3] = [("curl (3 fields)", CURL), ("browser (15 fields)", BROWSER), ("20 fields", &twenty)];
63 let best = level();
64 println!("scan level detected: {best:?}");
65 println!("{:<22} {:>6} {:>12} {:>12} {:>14} {:>9}", "request", "bytes", "simd ns", "scalar ns", "cameleer ns", "GB/s simd");
66 for (name, req) in cases {
67 assert!(cameleer::parse(req).is_ok());
68 force(best);
69 let simd = measure(|| {
70 black_box(simoom(req));
71 });
72 force(Level::Scalar);
73 let scalar = measure(|| {
74 black_box(simoom(req));
75 });
76 force(best);
77 let cam = measure(|| {
78 black_box(cameleer::parse(black_box(req)).ok());
79 });
80 println!(
81 "{name:<22} {:>6} {simd:>12.1} {scalar:>12.1} {cam:>14.1} {:>9.2}",
82 req.len(),
83 req.len() as f64 / simd
84 );
85 }
86 // Serialization.
87 let date = DateCache::new(1_700_000_000);
88 let mut out = Vec::with_capacity(256);
89 let head = measure(|| {
90 out.clear();
91 let mut w = HeadWriter::response(&mut out, 200);
92 w.header(b"Content-Type", b"application/json").unwrap().date(&date).content_length(1234);
93 w.finish();
94 black_box(&out);
95 });
96 let mut fixed = StaticHead::new(200, &[(b"Content-Type", b"text/plain"), (b"Server", b"simoom")], b"Hello, World!").unwrap();
97 let mut secs = 1_700_000_000;
98 let mut dc = DateCache::new(secs);
99 let stat = measure(|| {
100 black_box(fixed.full(&dc).len());
101 });
102 let stat_tick = measure(|| {
103 secs += 1;
104 dc.update(secs);
105 black_box(fixed.full(&dc).len());
106 });
107 println!("HeadWriter (status, 1 field, Date, Content-Length): {head:.1} ns");
108 println!("StaticHead::full (fixed reply, same second): {stat:.1} ns; with a new second every call: {stat_tick:.1} ns");
109}Sourcepub fn full(&mut self, date: &DateCache) -> &[u8] ⓘ
pub fn full(&mut self, date: &DateCache) -> &[u8] ⓘ
The whole reply, head and body.
Examples found in repository?
examples/bench_parse.rs (line 100)
60fn main() {
61 let twenty = twenty_headers();
62 let cases: [(&str, &[u8]); 3] = [("curl (3 fields)", CURL), ("browser (15 fields)", BROWSER), ("20 fields", &twenty)];
63 let best = level();
64 println!("scan level detected: {best:?}");
65 println!("{:<22} {:>6} {:>12} {:>12} {:>14} {:>9}", "request", "bytes", "simd ns", "scalar ns", "cameleer ns", "GB/s simd");
66 for (name, req) in cases {
67 assert!(cameleer::parse(req).is_ok());
68 force(best);
69 let simd = measure(|| {
70 black_box(simoom(req));
71 });
72 force(Level::Scalar);
73 let scalar = measure(|| {
74 black_box(simoom(req));
75 });
76 force(best);
77 let cam = measure(|| {
78 black_box(cameleer::parse(black_box(req)).ok());
79 });
80 println!(
81 "{name:<22} {:>6} {simd:>12.1} {scalar:>12.1} {cam:>14.1} {:>9.2}",
82 req.len(),
83 req.len() as f64 / simd
84 );
85 }
86 // Serialization.
87 let date = DateCache::new(1_700_000_000);
88 let mut out = Vec::with_capacity(256);
89 let head = measure(|| {
90 out.clear();
91 let mut w = HeadWriter::response(&mut out, 200);
92 w.header(b"Content-Type", b"application/json").unwrap().date(&date).content_length(1234);
93 w.finish();
94 black_box(&out);
95 });
96 let mut fixed = StaticHead::new(200, &[(b"Content-Type", b"text/plain"), (b"Server", b"simoom")], b"Hello, World!").unwrap();
97 let mut secs = 1_700_000_000;
98 let mut dc = DateCache::new(secs);
99 let stat = measure(|| {
100 black_box(fixed.full(&dc).len());
101 });
102 let stat_tick = measure(|| {
103 secs += 1;
104 dc.update(secs);
105 black_box(fixed.full(&dc).len());
106 });
107 println!("HeadWriter (status, 1 field, Date, Content-Length): {head:.1} ns");
108 println!("StaticHead::full (fixed reply, same second): {stat:.1} ns; with a new second every call: {stat_tick:.1} ns");
109}Trait Implementations§
Source§impl Clone for StaticHead
impl Clone for StaticHead
Auto Trait Implementations§
impl Forget for StaticHead
impl Freeze for StaticHead
impl Move for StaticHead
impl RefUnwindSafe for StaticHead
impl Send for StaticHead
impl Sync for StaticHead
impl Unpin for StaticHead
impl UnsafeUnpin for StaticHead
impl UnwindSafe for StaticHead
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more