Skip to content

Commit 5a00785

Browse files
committed
num: add minimal benchmarks for full floating-point formatting
We have benchmarks for the floating-point formatting algorithms themselves, but not for the surrounding machinery like Formatter and translating to the flt2dec::Part slices.
1 parent ad1461e commit 5a00785

File tree

1 file changed

+24
-0
lines changed
  • src/libcore/benches/num/flt2dec

1 file changed

+24
-0
lines changed

src/libcore/benches/num/flt2dec/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ mod strategy {
1313
mod grisu;
1414
}
1515

16+
use std::f64;
17+
use std::io::Write;
18+
use std::vec::Vec;
19+
use test::Bencher;
1620
use core::num::flt2dec::{decode, DecodableFloat, FullDecoded, Decoded};
1721
use core::num::flt2dec::MAX_SIG_DIGITS;
1822

@@ -22,3 +26,23 @@ pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
2226
full_decoded => panic!("expected finite, got {:?} instead", full_decoded)
2327
}
2428
}
29+
30+
#[bench]
31+
fn bench_small_shortest(b: &mut Bencher) {
32+
let mut buf = Vec::with_capacity(20);
33+
34+
b.iter(|| {
35+
buf.clear();
36+
write!(&mut buf, "{}", 3.1415926f64).unwrap()
37+
});
38+
}
39+
40+
#[bench]
41+
fn bench_big_shortest(b: &mut Bencher) {
42+
let mut buf = Vec::with_capacity(300);
43+
44+
b.iter(|| {
45+
buf.clear();
46+
write!(&mut buf, "{}", f64::MAX).unwrap()
47+
});
48+
}

0 commit comments

Comments
 (0)