Eliminate itoa::write and itoa::fmt from benches

This commit is contained in:
David Tolnay 2021-12-11 20:44:57 -08:00
parent 1898210ac6
commit 259ae8a794
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
1 changed files with 6 additions and 21 deletions

View File

@ -11,33 +11,17 @@ macro_rules! benches {
$name:ident($value:expr) $name:ident($value:expr)
),* ),*
) => { ) => {
mod bench_itoa_write { mod bench_itoa_format {
use test::{Bencher, black_box}; use test::{Bencher, black_box};
$( $(
$(#[$attr])* $(#[$attr])*
#[bench] #[bench]
fn $name(b: &mut Bencher) { fn $name(b: &mut Bencher) {
let mut buf = Vec::with_capacity(40); let mut buffer = itoa::Buffer::new();
b.iter(|| { b.iter(|| {
buf.clear(); let printed = buffer.format(black_box($value));
itoa::write(&mut buf, black_box($value)).unwrap() black_box(printed);
});
}
)*
}
mod bench_itoa_fmt {
use test::{Bencher, black_box};
$(
$(#[$attr])*
#[bench]
fn $name(b: &mut Bencher) {
let mut buf = String::with_capacity(40);
b.iter(|| {
buf.clear();
itoa::fmt(&mut buf, black_box($value)).unwrap()
}); });
} }
)* )*
@ -55,7 +39,8 @@ macro_rules! benches {
b.iter(|| { b.iter(|| {
buf.clear(); buf.clear();
write!(&mut buf, "{}", black_box($value)).unwrap() write!(&mut buf, "{}", black_box($value)).unwrap();
black_box(&buf);
}); });
} }
)* )*