2017-02-03 17:04:22 -06:00
|
|
|
mod strategy {
|
|
|
|
mod dragon;
|
|
|
|
mod grisu;
|
|
|
|
}
|
|
|
|
|
2019-12-06 22:18:12 -06:00
|
|
|
use core::num::flt2dec::MAX_SIG_DIGITS;
|
|
|
|
use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
|
2017-04-13 20:33:24 -05:00
|
|
|
use std::io::Write;
|
|
|
|
use std::vec::Vec;
|
|
|
|
use test::Bencher;
|
2017-02-03 17:04:22 -06:00
|
|
|
|
|
|
|
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
|
|
|
|
match decode(v).1 {
|
|
|
|
FullDecoded::Finite(decoded) => decoded,
|
2022-02-12 13:16:17 -06:00
|
|
|
full_decoded => panic!("expected finite, got {full_decoded:?} instead"),
|
2017-02-03 17:04:22 -06:00
|
|
|
}
|
|
|
|
}
|
2017-04-13 20:33:24 -05:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_small_shortest(b: &mut Bencher) {
|
|
|
|
let mut buf = Vec::with_capacity(20);
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
buf.clear();
|
|
|
|
write!(&mut buf, "{}", 3.1415926f64).unwrap()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_big_shortest(b: &mut Bencher) {
|
|
|
|
let mut buf = Vec::with_capacity(300);
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
buf.clear();
|
|
|
|
write!(&mut buf, "{}", f64::MAX).unwrap()
|
|
|
|
});
|
|
|
|
}
|