summaryrefslogtreecommitdiffstats
path: root/library/core/benches/char/methods.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/core/benches/char/methods.rs')
-rw-r--r--library/core/benches/char/methods.rs40
1 files changed, 26 insertions, 14 deletions
diff --git a/library/core/benches/char/methods.rs b/library/core/benches/char/methods.rs
index 9408f83c3..5d4df1ac8 100644
--- a/library/core/benches/char/methods.rs
+++ b/library/core/benches/char/methods.rs
@@ -1,26 +1,26 @@
-use test::Bencher;
+use test::{black_box, Bencher};
const CHARS: [char; 9] = ['0', 'x', '2', '5', 'A', 'f', '7', '8', '9'];
const RADIX: [u32; 5] = [2, 8, 10, 16, 32];
#[bench]
fn bench_to_digit_radix_2(b: &mut Bencher) {
- b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(2)).min())
+ b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(2)).min())
}
#[bench]
fn bench_to_digit_radix_10(b: &mut Bencher) {
- b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(10)).min())
+ b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(10)).min())
}
#[bench]
fn bench_to_digit_radix_16(b: &mut Bencher) {
- b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(16)).min())
+ b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(16)).min())
}
#[bench]
fn bench_to_digit_radix_36(b: &mut Bencher) {
- b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(36)).min())
+ b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_digit(36)).min())
}
#[bench]
@@ -31,47 +31,59 @@ fn bench_to_digit_radix_var(b: &mut Bencher) {
.cycle()
.zip(RADIX.iter().cycle())
.take(10_000)
- .map(|(c, radix)| c.to_digit(*radix))
+ .map(|(c, radix)| black_box(c).to_digit(*radix))
.min()
})
}
#[bench]
fn bench_to_ascii_uppercase(b: &mut Bencher) {
- b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_ascii_uppercase()).min())
+ b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_ascii_uppercase()).min())
}
#[bench]
fn bench_to_ascii_lowercase(b: &mut Bencher) {
- b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_ascii_lowercase()).min())
+ b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| black_box(c).to_ascii_lowercase()).min())
}
#[bench]
fn bench_ascii_mix_to_uppercase(b: &mut Bencher) {
- b.iter(|| (0..=255).cycle().take(10_000).map(|b| char::from(b).to_uppercase()).count())
+ b.iter(|| {
+ (0..=255).cycle().take(10_000).map(|b| black_box(char::from(b)).to_uppercase()).count()
+ })
}
#[bench]
fn bench_ascii_mix_to_lowercase(b: &mut Bencher) {
- b.iter(|| (0..=255).cycle().take(10_000).map(|b| char::from(b).to_lowercase()).count())
+ b.iter(|| {
+ (0..=255).cycle().take(10_000).map(|b| black_box(char::from(b)).to_lowercase()).count()
+ })
}
#[bench]
fn bench_ascii_char_to_uppercase(b: &mut Bencher) {
- b.iter(|| (0..=127).cycle().take(10_000).map(|b| char::from(b).to_uppercase()).count())
+ b.iter(|| {
+ (0..=127).cycle().take(10_000).map(|b| black_box(char::from(b)).to_uppercase()).count()
+ })
}
#[bench]
fn bench_ascii_char_to_lowercase(b: &mut Bencher) {
- b.iter(|| (0..=127).cycle().take(10_000).map(|b| char::from(b).to_lowercase()).count())
+ b.iter(|| {
+ (0..=127).cycle().take(10_000).map(|b| black_box(char::from(b)).to_lowercase()).count()
+ })
}
#[bench]
fn bench_non_ascii_char_to_uppercase(b: &mut Bencher) {
- b.iter(|| (128..=255).cycle().take(10_000).map(|b| char::from(b).to_uppercase()).count())
+ b.iter(|| {
+ (128..=255).cycle().take(10_000).map(|b| black_box(char::from(b)).to_uppercase()).count()
+ })
}
#[bench]
fn bench_non_ascii_char_to_lowercase(b: &mut Bencher) {
- b.iter(|| (128..=255).cycle().take(10_000).map(|b| char::from(b).to_lowercase()).count())
+ b.iter(|| {
+ (128..=255).cycle().take(10_000).map(|b| black_box(char::from(b)).to_lowercase()).count()
+ })
}