Skip to content

Commit c6ba5c0

Browse files
5225225pyfisch
authored andcommitted
Remove allocation in encode_date benchmark
1 parent 1230e55 commit c6ba5c0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

benches/benchmarks.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ pub fn parse_asctime(c: &mut Criterion) {
2727
});
2828
}
2929

30+
struct BlackBoxWrite;
31+
32+
impl 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+
3039
pub fn encode_date(c: &mut Criterion) {
3140
c.bench_function("encode_date", |b| {
3241
let d = "Wed, 21 Oct 2015 07:28:00 GMT";
3342
black_box(httpdate::parse_http_date(d)).unwrap();
3443
b.iter(|| {
35-
black_box(format!("{}", black_box(d)));
44+
use std::fmt::Write;
45+
let _ = write!(BlackBoxWrite, "{}", d);
3646
})
3747
});
3848
}

0 commit comments

Comments
 (0)