rust/library/core/benches/num/flt2dec/mod.rs
T-O-R-U-S 72a25d05bf Use implicit capture syntax in format_args
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
2022-03-10 10:23:40 -05:00

38 lines
830 B
Rust

mod strategy {
mod dragon;
mod grisu;
}
use core::num::flt2dec::MAX_SIG_DIGITS;
use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
use std::io::Write;
use std::vec::Vec;
use test::Bencher;
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
match decode(v).1 {
FullDecoded::Finite(decoded) => decoded,
full_decoded => panic!("expected finite, got {full_decoded:?} instead"),
}
}
#[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()
});
}