@@ -12,7 +12,14 @@ fn branchless_to_ascii_upper_case(byte: u8) -> u8 {
12
12
13
13
14
14
macro_rules! benches {
15
- ( $( fn $name: ident( $arg: ident: & mut [ u8 ] ) $body: block ) +) => {
15
+ ( $( fn $name: ident( $arg: ident: & mut [ u8 ] ) $body: block ) + @iter $( $is_: ident, ) +) => {
16
+ benches! { @
17
+ $( fn $name( $arg: & mut [ u8 ] ) $body ) +
18
+ $( fn $is_( bytes: & mut [ u8 ] ) { bytes. iter( ) . all( u8 :: $is_) } ) +
19
+ }
20
+ } ;
21
+
22
+ ( @$( fn $name: ident( $arg: ident: & mut [ u8 ] ) $body: block ) +) => {
16
23
benches!( mod short SHORT $( $name $arg $body) +) ;
17
24
benches!( mod medium MEDIUM $( $name $arg $body) +) ;
18
25
benches!( mod long LONG $( $name $arg $body) +) ;
@@ -30,7 +37,7 @@ macro_rules! benches {
30
37
let mut vec = $input. as_bytes( ) . to_vec( ) ;
31
38
{
32
39
let $arg = & mut vec[ ..] ;
33
- $body
40
+ black_box ( $body) ;
34
41
}
35
42
vec
36
43
} )
@@ -44,21 +51,21 @@ use test::black_box;
44
51
use test:: Bencher ;
45
52
46
53
benches ! {
47
- fn bench00_alloc_only ( _bytes: & mut [ u8 ] ) { }
54
+ fn case00_alloc_only ( _bytes: & mut [ u8 ] ) { }
48
55
49
- fn bench01_black_box_read_each_byte ( bytes: & mut [ u8 ] ) {
56
+ fn case01_black_box_read_each_byte ( bytes: & mut [ u8 ] ) {
50
57
for byte in bytes {
51
58
black_box( * byte) ;
52
59
}
53
60
}
54
61
55
- fn bench02_lookup ( bytes: & mut [ u8 ] ) {
62
+ fn case02_lookup ( bytes: & mut [ u8 ] ) {
56
63
for byte in bytes {
57
64
* byte = ASCII_UPPERCASE_MAP [ * byte as usize ]
58
65
}
59
66
}
60
67
61
- fn bench03_branch_and_subtract ( bytes: & mut [ u8 ] ) {
68
+ fn case03_branch_and_subtract ( bytes: & mut [ u8 ] ) {
62
69
for byte in bytes {
63
70
* byte = if b'a' <= * byte && * byte <= b'z' {
64
71
* byte - b'a' + b'A'
@@ -68,7 +75,7 @@ benches! {
68
75
}
69
76
}
70
77
71
- fn bench04_branch_and_mask ( bytes: & mut [ u8 ] ) {
78
+ fn case04_branch_and_mask ( bytes: & mut [ u8 ] ) {
72
79
for byte in bytes {
73
80
* byte = if b'a' <= * byte && * byte <= b'z' {
74
81
* byte & !0x20
@@ -78,23 +85,17 @@ benches! {
78
85
}
79
86
}
80
87
81
- fn bench05_branchless ( bytes: & mut [ u8 ] ) {
88
+ fn case05_branchless ( bytes: & mut [ u8 ] ) {
82
89
for byte in bytes {
83
90
* byte = branchless_to_ascii_upper_case( * byte)
84
91
}
85
92
}
86
93
87
- fn bench05_multiply_by_bool( bytes: & mut [ u8 ] ) {
88
- for byte in bytes {
89
- * byte &= !( 0x20 * ( b'a' <= * byte && * byte <= b'z' ) as u8 )
90
- }
91
- }
92
-
93
- fn bench06_libcore( bytes: & mut [ u8 ] ) {
94
+ fn case06_libcore( bytes: & mut [ u8 ] ) {
94
95
bytes. make_ascii_uppercase( )
95
96
}
96
97
97
- fn bench07_fake_simd_u32 ( bytes: & mut [ u8 ] ) {
98
+ fn case07_fake_simd_u32 ( bytes: & mut [ u8 ] ) {
98
99
let ( before, aligned, after) = unsafe {
99
100
bytes. align_to_mut:: <u32 >( )
100
101
} ;
@@ -118,7 +119,7 @@ benches! {
118
119
}
119
120
}
120
121
121
- fn bench08_fake_simd_u64 ( bytes: & mut [ u8 ] ) {
122
+ fn case08_fake_simd_u64 ( bytes: & mut [ u8 ] ) {
122
123
let ( before, aligned, after) = unsafe {
123
124
bytes. align_to_mut:: <u64 >( )
124
125
} ;
@@ -139,6 +140,20 @@ benches! {
139
140
* byte = branchless_to_ascii_upper_case( * byte)
140
141
}
141
142
}
143
+
144
+ @iter
145
+
146
+ is_ascii,
147
+ is_ascii_alphabetic,
148
+ is_ascii_uppercase,
149
+ is_ascii_lowercase,
150
+ is_ascii_alphanumeric,
151
+ is_ascii_digit,
152
+ is_ascii_hexdigit,
153
+ is_ascii_punctuation,
154
+ is_ascii_graphic,
155
+ is_ascii_whitespace,
156
+ is_ascii_control,
142
157
}
143
158
144
159
macro_rules! repeat {
0 commit comments