message: test(h1): add benchmarks for server date checking and rendering
diff: @@ -59,11 +59,15 @@ impl CachedDate {
  }
  fn update(&mut self, now: time::Timespec) {
  + self.render(now);
  + self.next_update = now + Duration::seconds(1);
  + self.next_update.nsec = 0;
  + }
  +
  + fn render(&mut self, now: time::Timespec) {
  self.pos = 0;
  let _ = write!(self, "{}", time::at_utc(now).rfc822());
  debug_assert!(self.pos == DATE_VALUE_LENGTH);
  - self.next_update = now + Duration::seconds(1);
  - self.next_update.nsec = 0;
  }
  }
  @@ -76,7 +80,41 @@ impl fmt::Write for CachedDate {
  }
  }
  +#[cfg(test)]
  +mod tests {
  + use super::*;
  +
  + #[cfg(feature = "nightly")]
  + use test::Bencher;
  +
  #[test]
  fn test_date_len() {
  assert_eq!(DATE_VALUE_LENGTH, "Sun, 06 Nov 1994 08:49:37 GMT".len());
  }
  +
  + #[cfg(feature = "nightly")]
  + #[bench]
  + fn bench_date_check(b: &mut Bencher) {
  + let mut date = CachedDate::new();
  + // cache the first update
  + date.check();
  +
  + b.iter(|| {
  + date.check();
  + });
  + }
  +
  + #[cfg(feature = "nightly")]
  + #[bench]
  + fn bench_date_render(b: &mut Bencher) {
  + let mut date = CachedDate::new();
  + let now = time::get_time();
  + date.render(now);
  + b.bytes = date.buffer().len() as u64;
  +
  + b.iter(|| {
  + date.render(now);
  + test::black_box(&date);
  + });
  + }
  +}
  