1use criterion::{black_box, criterion_group, criterion_main, Criterion};
2
3pub fn parse_imf_fixdate(c: &mut Criterion) {
4 c.bench_function("parse_imf_fixdate", |b| {
5 b.iter(|| {
6 let d = black_box("Sun, 06 Nov 1994 08:49:37 GMT");
7 black_box(httpdate::parse_http_date(d)).unwrap();
8 })
9 });
10}
11
12pub fn parse_rfc850_date(c: &mut Criterion) {
13 c.bench_function("parse_rfc850_date", |b| {
14 b.iter(|| {
15 let d = black_box("Sunday, 06-Nov-94 08:49:37 GMT");
16 black_box(httpdate::parse_http_date(d)).unwrap();
17 })
18 });
19}
20
21pub fn parse_asctime(c: &mut Criterion) {
22 c.bench_function("parse_asctime", |b| {
23 b.iter(|| {
24 let d = black_box("Sun Nov 6 08:49:37 1994");
25 black_box(httpdate::parse_http_date(d)).unwrap();
26 })
27 });
28}
29
30struct BlackBoxWrite;
31
32impl std::fmt::Write for BlackBoxWrite {
33 fn write_str(&mut self, s: &str) -> Result<(), std::fmt::Error> {
34 black_box(s);
35 Ok(())
36 }
37}
38
39pub fn encode_date(c: &mut Criterion) {
40 c.bench_function("encode_date", |b| {
41 let d = "Wed, 21 Oct 2015 07:28:00 GMT";
42 black_box(httpdate::parse_http_date(d)).unwrap();
43 b.iter(|| {
44 use std::fmt::Write;
45 let _ = write!(BlackBoxWrite, "{}", d);
46 })
47 });
48}
49
50criterion_group!(
51 benches,
52 parse_imf_fixdate,
53 parse_rfc850_date,
54 parse_asctime,
55 encode_date
56);
57criterion_main!(benches);
58