Benchmark for itoa::fmt

This commit is contained in:
David Tolnay 2018-03-18 00:25:02 -07:00
parent ef180dc6e7
commit c7c3caf3b9
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
1 changed files with 20 additions and 2 deletions

View File

@ -15,7 +15,7 @@ macro_rules! benches {
$name:ident($value:expr) $name:ident($value:expr)
),* ),*
) => { ) => {
mod bench_itoa { mod bench_itoa_write {
use test::{Bencher, black_box}; use test::{Bencher, black_box};
$( $(
$(#[$attr])* $(#[$attr])*
@ -33,7 +33,25 @@ macro_rules! benches {
)* )*
} }
mod bench_fmt { mod bench_itoa_fmt {
use test::{Bencher, black_box};
$(
$(#[$attr])*
#[bench]
fn $name(b: &mut Bencher) {
use itoa;
let mut buf = String::with_capacity(40);
b.iter(|| {
buf.clear();
itoa::fmt(&mut buf, black_box($value)).unwrap()
});
}
)*
}
mod bench_std_fmt {
use test::{Bencher, black_box}; use test::{Bencher, black_box};
$( $(
$(#[$attr])* $(#[$attr])*