]>
git.proxmox.com Git - rustc.git/blob - src/libcore/benches/num/flt2dec/strategy/grisu.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use core
::num
::flt2dec
::strategy
::grisu
::*;
16 pub fn decode_finite
<T
: DecodableFloat
>(v
: T
) -> Decoded
{
18 FullDecoded
::Finite(decoded
) => decoded
,
19 full_decoded
=> panic
!("expected finite, got {:?} instead", full_decoded
)
24 fn bench_small_shortest(b
: &mut Bencher
) {
25 let decoded
= decode_finite(3.141592f64);
26 let mut buf
= [0; MAX_SIG_DIGITS
];
27 b
.iter(|| format_shortest(&decoded
, &mut buf
));
31 fn bench_big_shortest(b
: &mut Bencher
) {
32 let decoded
= decode_finite(f64::MAX
);
33 let mut buf
= [0; MAX_SIG_DIGITS
];
34 b
.iter(|| format_shortest(&decoded
, &mut buf
));
38 fn bench_small_exact_3(b
: &mut Bencher
) {
39 let decoded
= decode_finite(3.141592f64);
41 b
.iter(|| format_exact(&decoded
, &mut buf
, i16::MIN
));
45 fn bench_big_exact_3(b
: &mut Bencher
) {
46 let decoded
= decode_finite(f64::MAX
);
48 b
.iter(|| format_exact(&decoded
, &mut buf
, i16::MIN
));
52 fn bench_small_exact_12(b
: &mut Bencher
) {
53 let decoded
= decode_finite(3.141592f64);
54 let mut buf
= [0; 12];
55 b
.iter(|| format_exact(&decoded
, &mut buf
, i16::MIN
));
59 fn bench_big_exact_12(b
: &mut Bencher
) {
60 let decoded
= decode_finite(f64::MAX
);
61 let mut buf
= [0; 12];
62 b
.iter(|| format_exact(&decoded
, &mut buf
, i16::MIN
));
66 fn bench_small_exact_inf(b
: &mut Bencher
) {
67 let decoded
= decode_finite(3.141592f64);
68 let mut buf
= [0; 1024];
69 b
.iter(|| format_exact(&decoded
, &mut buf
, i16::MIN
));
73 fn bench_big_exact_inf(b
: &mut Bencher
) {
74 let decoded
= decode_finite(f64::MAX
);
75 let mut buf
= [0; 1024];
76 b
.iter(|| format_exact(&decoded
, &mut buf
, i16::MIN
));