pub struct DateCache { /* private fields */ }Expand description
The Date value, formatted once per second. The caller owns the clock: call
update with the current Unix time, typically once per loop tick.
Implementations§
Source§impl DateCache
impl DateCache
Sourcepub fn new(unix_secs: u64) -> Self
pub fn new(unix_secs: u64) -> Self
A cache holding the date for unix_secs.
Examples found in repository?
examples/bench_parse.rs (line 87)
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 update(&mut self, unix_secs: u64) -> bool
pub fn update(&mut self, unix_secs: u64) -> bool
Moves to unix_secs; formats only when the second changed. Returns true if it did.
Examples found in repository?
examples/bench_parse.rs (line 104)
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§
Auto Trait Implementations§
impl Forget for DateCache
impl Freeze for DateCache
impl Move for DateCache
impl RefUnwindSafe for DateCache
impl Send for DateCache
impl Sync for DateCache
impl Unpin for DateCache
impl UnsafeUnpin for DateCache
impl UnwindSafe for DateCache
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