@@ -12,7 +12,14 @@ fn branchless_to_ascii_upper_case(byte: u8) -> u8 {
1212
1313
1414macro_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 ) +) => {
1623 benches!( mod short SHORT $( $name $arg $body) +) ;
1724 benches!( mod medium MEDIUM $( $name $arg $body) +) ;
1825 benches!( mod long LONG $( $name $arg $body) +) ;
@@ -30,7 +37,7 @@ macro_rules! benches {
3037 let mut vec = $input. as_bytes( ) . to_vec( ) ;
3138 {
3239 let $arg = & mut vec[ ..] ;
33- $body
40+ black_box ( $body) ;
3441 }
3542 vec
3643 } )
@@ -44,21 +51,21 @@ use test::black_box;
4451use test:: Bencher ;
4552
4653benches ! {
47- fn bench00_alloc_only ( _bytes: & mut [ u8 ] ) { }
54+ fn case00_alloc_only ( _bytes: & mut [ u8 ] ) { }
4855
49- fn bench01_black_box_read_each_byte ( bytes: & mut [ u8 ] ) {
56+ fn case01_black_box_read_each_byte ( bytes: & mut [ u8 ] ) {
5057 for byte in bytes {
5158 black_box( * byte) ;
5259 }
5360 }
5461
55- fn bench02_lookup ( bytes: & mut [ u8 ] ) {
62+ fn case02_lookup ( bytes: & mut [ u8 ] ) {
5663 for byte in bytes {
5764 * byte = ASCII_UPPERCASE_MAP [ * byte as usize ]
5865 }
5966 }
6067
61- fn bench03_branch_and_subtract ( bytes: & mut [ u8 ] ) {
68+ fn case03_branch_and_subtract ( bytes: & mut [ u8 ] ) {
6269 for byte in bytes {
6370 * byte = if b'a' <= * byte && * byte <= b'z' {
6471 * byte - b'a' + b'A'
@@ -68,7 +75,7 @@ benches! {
6875 }
6976 }
7077
71- fn bench04_branch_and_mask ( bytes: & mut [ u8 ] ) {
78+ fn case04_branch_and_mask ( bytes: & mut [ u8 ] ) {
7279 for byte in bytes {
7380 * byte = if b'a' <= * byte && * byte <= b'z' {
7481 * byte & !0x20
@@ -78,23 +85,17 @@ benches! {
7885 }
7986 }
8087
81- fn bench05_branchless ( bytes: & mut [ u8 ] ) {
88+ fn case05_branchless ( bytes: & mut [ u8 ] ) {
8289 for byte in bytes {
8390 * byte = branchless_to_ascii_upper_case( * byte)
8491 }
8592 }
8693
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 ] ) {
9495 bytes. make_ascii_uppercase( )
9596 }
9697
97- fn bench07_fake_simd_u32 ( bytes: & mut [ u8 ] ) {
98+ fn case07_fake_simd_u32 ( bytes: & mut [ u8 ] ) {
9899 let ( before, aligned, after) = unsafe {
99100 bytes. align_to_mut:: <u32 >( )
100101 } ;
@@ -118,7 +119,7 @@ benches! {
118119 }
119120 }
120121
121- fn bench08_fake_simd_u64 ( bytes: & mut [ u8 ] ) {
122+ fn case08_fake_simd_u64 ( bytes: & mut [ u8 ] ) {
122123 let ( before, aligned, after) = unsafe {
123124 bytes. align_to_mut:: <u64 >( )
124125 } ;
@@ -139,6 +140,20 @@ benches! {
139140 * byte = branchless_to_ascii_upper_case( * byte)
140141 }
141142 }
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,
142157}
143158
144159macro_rules! repeat {
0 commit comments