File: methods.rs

package info (click to toggle)
rustc-web 1.85.0%2Bdfsg3-1~deb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,759,988 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,056; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (89 lines) | stat: -rw-r--r-- 2,443 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use test::{Bencher, black_box};

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| 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| 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| 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| black_box(c).to_digit(36)).min())
}

#[bench]
fn bench_to_digit_radix_var(b: &mut Bencher) {
    b.iter(|| {
        CHARS
            .iter()
            .cycle()
            .zip(RADIX.iter().cycle())
            .take(10_000)
            .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| 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| 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| 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| 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| 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| 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| 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| black_box(char::from(b)).to_lowercase()).count()
    })
}