summaryrefslogtreecommitdiffstats
path: root/library/core/benches
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
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')
-rw-r--r--library/core/benches/fmt.rs24
-rw-r--r--library/core/benches/iter.rs46
-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
6 files changed, 101 insertions, 32 deletions
diff --git a/library/core/benches/fmt.rs b/library/core/benches/fmt.rs
index ff726ff75..d1cdb12e5 100644
--- a/library/core/benches/fmt.rs
+++ b/library/core/benches/fmt.rs
@@ -1,13 +1,13 @@
use std::fmt::{self, Write as FmtWrite};
use std::io::{self, Write as IoWrite};
-use test::Bencher;
+use test::{black_box, Bencher};
#[bench]
fn write_vec_value(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = Vec::new();
for _ in 0..1000 {
- mem.write_all("abc".as_bytes()).unwrap();
+ mem.write_all(black_box("abc").as_bytes()).unwrap();
}
});
}
@@ -18,7 +18,7 @@ fn write_vec_ref(bh: &mut Bencher) {
let mut mem = Vec::new();
let wr = &mut mem as &mut dyn io::Write;
for _ in 0..1000 {
- wr.write_all("abc".as_bytes()).unwrap();
+ wr.write_all(black_box("abc").as_bytes()).unwrap();
}
});
}
@@ -29,7 +29,7 @@ fn write_vec_macro1(bh: &mut Bencher) {
let mut mem = Vec::new();
let wr = &mut mem as &mut dyn io::Write;
for _ in 0..1000 {
- write!(wr, "abc").unwrap();
+ write!(wr, "{}", black_box("abc")).unwrap();
}
});
}
@@ -40,7 +40,7 @@ fn write_vec_macro2(bh: &mut Bencher) {
let mut mem = Vec::new();
let wr = &mut mem as &mut dyn io::Write;
for _ in 0..1000 {
- write!(wr, "{}", "abc").unwrap();
+ write!(wr, "{}", black_box("abc")).unwrap();
}
});
}
@@ -51,7 +51,7 @@ fn write_vec_macro_debug(bh: &mut Bencher) {
let mut mem = Vec::new();
let wr = &mut mem as &mut dyn io::Write;
for _ in 0..1000 {
- write!(wr, "{:?}", "☃").unwrap();
+ write!(wr, "{:?}", black_box("☃")).unwrap();
}
});
}
@@ -61,7 +61,7 @@ fn write_str_value(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = String::new();
for _ in 0..1000 {
- mem.write_str("abc").unwrap();
+ mem.write_str(black_box("abc")).unwrap();
}
});
}
@@ -72,7 +72,7 @@ fn write_str_ref(bh: &mut Bencher) {
let mut mem = String::new();
let wr = &mut mem as &mut dyn fmt::Write;
for _ in 0..1000 {
- wr.write_str("abc").unwrap();
+ wr.write_str(black_box("abc")).unwrap();
}
});
}
@@ -82,7 +82,7 @@ fn write_str_macro1(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = String::new();
for _ in 0..1000 {
- write!(mem, "abc").unwrap();
+ write!(mem, "{}", black_box("abc")).unwrap();
}
});
}
@@ -93,7 +93,7 @@ fn write_str_macro2(bh: &mut Bencher) {
let mut mem = String::new();
let wr = &mut mem as &mut dyn fmt::Write;
for _ in 0..1000 {
- write!(wr, "{}", "abc").unwrap();
+ write!(wr, "{}", black_box("abc")).unwrap();
}
});
}
@@ -104,7 +104,7 @@ fn write_str_macro_debug(bh: &mut Bencher) {
let mut mem = String::new();
let wr = &mut mem as &mut dyn fmt::Write;
for _ in 0..1000 {
- write!(wr, "{:?}", "☃").unwrap();
+ write!(wr, "{:?}", black_box("☃")).unwrap();
}
});
}
@@ -115,7 +115,7 @@ fn write_str_macro_debug_ascii(bh: &mut Bencher) {
let mut mem = String::new();
let wr = &mut mem as &mut dyn fmt::Write;
for _ in 0..1000 {
- write!(wr, "{:?}", "Hello, World!").unwrap();
+ write!(wr, "{:?}", black_box("Hello, World!")).unwrap();
}
});
}
diff --git a/library/core/benches/iter.rs b/library/core/benches/iter.rs
index 9193c79be..60ef83223 100644
--- a/library/core/benches/iter.rs
+++ b/library/core/benches/iter.rs
@@ -404,7 +404,7 @@ fn bench_trusted_random_access_adapters(b: &mut Bencher) {
/// Exercises the iter::Copied specialization for slice::Iter
#[bench]
-fn bench_copied_chunks(b: &mut Bencher) {
+fn bench_next_chunk_copied(b: &mut Bencher) {
let v = vec![1u8; 1024];
b.iter(|| {
@@ -421,7 +421,7 @@ fn bench_copied_chunks(b: &mut Bencher) {
/// Exercises the TrustedRandomAccess specialization in ArrayChunks
#[bench]
-fn bench_trusted_random_access_chunks(b: &mut Bencher) {
+fn bench_next_chunk_trusted_random_access(b: &mut Bencher) {
let v = vec![1u8; 1024];
b.iter(|| {
@@ -437,3 +437,45 @@ fn bench_trusted_random_access_chunks(b: &mut Bencher) {
.sum::<Wrapping<u64>>()
})
}
+
+#[bench]
+fn bench_next_chunk_filter_even(b: &mut Bencher) {
+ let a = (0..1024).next_chunk::<1024>().unwrap();
+
+ b.iter(|| black_box(&a).iter().filter(|&&i| i % 2 == 0).next_chunk::<32>())
+}
+
+#[bench]
+fn bench_next_chunk_filter_predictably_true(b: &mut Bencher) {
+ let a = (0..1024).next_chunk::<1024>().unwrap();
+
+ b.iter(|| black_box(&a).iter().filter(|&&i| i < 100).next_chunk::<32>())
+}
+
+#[bench]
+fn bench_next_chunk_filter_mostly_false(b: &mut Bencher) {
+ let a = (0..1024).next_chunk::<1024>().unwrap();
+
+ b.iter(|| black_box(&a).iter().filter(|&&i| i > 900).next_chunk::<32>())
+}
+
+#[bench]
+fn bench_next_chunk_filter_map_even(b: &mut Bencher) {
+ let a = (0..1024).next_chunk::<1024>().unwrap();
+
+ b.iter(|| black_box(&a).iter().filter_map(|&i| (i % 2 == 0).then(|| i)).next_chunk::<32>())
+}
+
+#[bench]
+fn bench_next_chunk_filter_map_predictably_true(b: &mut Bencher) {
+ let a = (0..1024).next_chunk::<1024>().unwrap();
+
+ b.iter(|| black_box(&a).iter().filter_map(|&i| (i < 100).then(|| i)).next_chunk::<32>())
+}
+
+#[bench]
+fn bench_next_chunk_filter_map_mostly_false(b: &mut Bencher) {
+ let a = (0..1024).next_chunk::<1024>().unwrap();
+
+ b.iter(|| black_box(&a).iter().filter_map(|&i| (i > 900).then(|| i)).next_chunk::<32>())
+}
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()
})
}