]> git.lizzy.rs Git - rust.git/blob - src/libcore/benches/num/flt2dec/strategy/grisu.rs
Rollup merge of #39604 - est31:i128_tests, r=alexcrichton
[rust.git] / 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.
4 //
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.
10
11 use std::{i16, f64};
12 use super::super::*;
13 use core::num::flt2dec::strategy::grisu::*;
14 use test::Bencher;
15
16 pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
17     match decode(v).1 {
18         FullDecoded::Finite(decoded) => decoded,
19         full_decoded => panic!("expected finite, got {:?} instead", full_decoded)
20     }
21 }
22
23 #[bench]
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));
28 }
29
30 #[bench]
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));
35 }
36
37 #[bench]
38 fn bench_small_exact_3(b: &mut Bencher) {
39     let decoded = decode_finite(3.141592f64);
40     let mut buf = [0; 3];
41     b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
42 }
43
44 #[bench]
45 fn bench_big_exact_3(b: &mut Bencher) {
46     let decoded = decode_finite(f64::MAX);
47     let mut buf = [0; 3];
48     b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
49 }
50
51 #[bench]
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));
56 }
57
58 #[bench]
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));
63 }
64
65 #[bench]
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));
70 }
71
72 #[bench]
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));
77 }