summaryrefslogtreecommitdiffstats
path: root/library/core/benches/num
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /library/core/benches/num
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/benches/num')
-rw-r--r--library/core/benches/num/dec2flt/mod.rs24
-rw-r--r--library/core/benches/num/flt2dec/mod.rs6
-rw-r--r--library/core/benches/num/flt2dec/strategy/grisu.rs27
-rw-r--r--library/core/benches/num/mod.rs6
4 files changed, 45 insertions, 18 deletions
diff --git a/library/core/benches/num/dec2flt/mod.rs b/library/core/benches/num/dec2flt/mod.rs
index 305baa687..fb4a786b2 100644
--- a/library/core/benches/num/dec2flt/mod.rs
+++ b/library/core/benches/num/dec2flt/mod.rs
@@ -1,57 +1,57 @@
-use test::Bencher;
+use test::{black_box, Bencher};
#[bench]
fn bench_0(b: &mut Bencher) {
- b.iter(|| "0.0".parse::<f64>());
+ b.iter(|| black_box("0.0").parse::<f64>());
}
#[bench]
fn bench_42(b: &mut Bencher) {
- b.iter(|| "42".parse::<f64>());
+ b.iter(|| black_box("42").parse::<f64>());
}
#[bench]
fn bench_huge_int(b: &mut Bencher) {
// 2^128 - 1
- b.iter(|| "170141183460469231731687303715884105727".parse::<f64>());
+ b.iter(|| black_box("170141183460469231731687303715884105727").parse::<f64>());
}
#[bench]
fn bench_short_decimal(b: &mut Bencher) {
- b.iter(|| "1234.5678".parse::<f64>());
+ b.iter(|| black_box("1234.5678").parse::<f64>());
}
#[bench]
fn bench_pi_long(b: &mut Bencher) {
- b.iter(|| "3.14159265358979323846264338327950288".parse::<f64>());
+ b.iter(|| black_box("3.14159265358979323846264338327950288").parse::<f64>());
}
#[bench]
fn bench_pi_short(b: &mut Bencher) {
- b.iter(|| "3.141592653589793".parse::<f64>())
+ b.iter(|| black_box("3.141592653589793").parse::<f64>())
}
#[bench]
fn bench_1e150(b: &mut Bencher) {
- b.iter(|| "1e150".parse::<f64>());
+ b.iter(|| black_box("1e150").parse::<f64>());
}
#[bench]
fn bench_long_decimal_and_exp(b: &mut Bencher) {
- b.iter(|| "727501488517303786137132964064381141071e-123".parse::<f64>());
+ b.iter(|| black_box("727501488517303786137132964064381141071e-123").parse::<f64>());
}
#[bench]
fn bench_min_subnormal(b: &mut Bencher) {
- b.iter(|| "5e-324".parse::<f64>());
+ b.iter(|| black_box("5e-324").parse::<f64>());
}
#[bench]
fn bench_min_normal(b: &mut Bencher) {
- b.iter(|| "2.2250738585072014e-308".parse::<f64>());
+ b.iter(|| black_box("2.2250738585072014e-308").parse::<f64>());
}
#[bench]
fn bench_max(b: &mut Bencher) {
- b.iter(|| "1.7976931348623157e308".parse::<f64>());
+ b.iter(|| black_box("1.7976931348623157e308").parse::<f64>());
}
diff --git a/library/core/benches/num/flt2dec/mod.rs b/library/core/benches/num/flt2dec/mod.rs
index 32fd5e626..1a330ef5f 100644
--- a/library/core/benches/num/flt2dec/mod.rs
+++ b/library/core/benches/num/flt2dec/mod.rs
@@ -7,7 +7,7 @@ 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;
+use test::{black_box, Bencher};
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
match decode(v).1 {
@@ -22,7 +22,7 @@ fn bench_small_shortest(b: &mut Bencher) {
b.iter(|| {
buf.clear();
- write!(&mut buf, "{}", 3.1415926f64).unwrap()
+ write!(black_box(&mut buf), "{}", black_box(3.1415926f64)).unwrap()
});
}
@@ -32,6 +32,6 @@ fn bench_big_shortest(b: &mut Bencher) {
b.iter(|| {
buf.clear();
- write!(&mut buf, "{}", f64::MAX).unwrap()
+ write!(black_box(&mut buf), "{}", black_box(f64::MAX)).unwrap()
});
}
diff --git a/library/core/benches/num/flt2dec/strategy/grisu.rs b/library/core/benches/num/flt2dec/strategy/grisu.rs
index 6bea5e55d..17d6b474a 100644
--- a/library/core/benches/num/flt2dec/strategy/grisu.rs
+++ b/library/core/benches/num/flt2dec/strategy/grisu.rs
@@ -81,3 +81,30 @@ fn bench_big_exact_inf(b: &mut Bencher) {
format_exact(black_box(&decoded), &mut buf, i16::MIN);
});
}
+
+#[bench]
+fn bench_one_exact_inf(b: &mut Bencher) {
+ let decoded = decode_finite(1.0);
+ let mut buf = [MaybeUninit::new(0); 1024];
+ b.iter(|| {
+ format_exact(black_box(&decoded), &mut buf, i16::MIN);
+ });
+}
+
+#[bench]
+fn bench_trailing_zero_exact_inf(b: &mut Bencher) {
+ let decoded = decode_finite(250.000000000000000000000000);
+ let mut buf = [MaybeUninit::new(0); 1024];
+ b.iter(|| {
+ format_exact(black_box(&decoded), &mut buf, i16::MIN);
+ });
+}
+
+#[bench]
+fn bench_halfway_point_exact_inf(b: &mut Bencher) {
+ let decoded = decode_finite(1.00000000000000011102230246251565404236316680908203125);
+ let mut buf = [MaybeUninit::new(0); 1024];
+ b.iter(|| {
+ format_exact(black_box(&decoded), &mut buf, i16::MIN);
+ });
+}
diff --git a/library/core/benches/num/mod.rs b/library/core/benches/num/mod.rs
index 2f9cad272..b97014d9b 100644
--- a/library/core/benches/num/mod.rs
+++ b/library/core/benches/num/mod.rs
@@ -3,7 +3,7 @@ mod flt2dec;
mod int_log;
use std::str::FromStr;
-use test::Bencher;
+use test::{black_box, Bencher};
const ASCII_NUMBERS: [&str; 19] = [
"0",
@@ -36,7 +36,7 @@ macro_rules! from_str_bench {
.iter()
.cycle()
.take(5_000)
- .filter_map(|s| <$t>::from_str(s).ok())
+ .filter_map(|s| <$t>::from_str(black_box(s)).ok())
.max()
})
}
@@ -52,7 +52,7 @@ macro_rules! from_str_radix_bench {
.iter()
.cycle()
.take(5_000)
- .filter_map(|s| <$t>::from_str_radix(s, $radix).ok())
+ .filter_map(|s| <$t>::from_str_radix(black_box(s), $radix).ok())
.max()
})
}