mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #108291 - chenyukang:yukang/fix-benchmarks, r=workingjubilee
Fix more benchmark test with black_box Follow up fix for https://github.com/rust-lang/rust/issues/107590
This commit is contained in:
commit
fc30207b16
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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>());
|
||||
}
|
||||
|
@ -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()
|
||||
});
|
||||
}
|
||||
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user