1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <ctype.h>
18 
19 #include <benchmark/benchmark.h>
20 #include "util.h"
21 
22 // Avoid optimization.
23 volatile int A = 'A';
24 volatile int a = 'a';
25 volatile int X = 'X';
26 volatile int x = 'x';
27 volatile int backspace = '\b';
28 volatile int del = '\x7f';
29 volatile int space = ' ';
30 volatile int tab = '\t';
31 volatile int zero = '0';
32 volatile int underscore = '_';
33 volatile int top_bit_set = 0x88;
34 
35 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isalnum_y1, isalnum(A));
36 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isalnum_y2, isalnum(a));
37 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isalnum_y3, isalnum(zero));
38 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isalnum_n, isalnum(underscore));
39 
40 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isalpha_y1, isalpha(A));
41 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isalpha_y2, isalpha(a));
42 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isalpha_n, isalpha(underscore));
43 
44 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isascii_y, isascii(x));
45 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isascii_n, isascii(top_bit_set));
46 
47 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isblank_y1, isblank(space));
48 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isblank_y2, isblank(tab));
49 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isblank_n, isblank(underscore));
50 
51 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_iscntrl_y1, iscntrl(backspace));
52 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_iscntrl_y2, iscntrl(del));
53 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_iscntrl_n, iscntrl(underscore));
54 
55 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isdigit_y, iscntrl(zero));
56 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isdigit_n, iscntrl(underscore));
57 
58 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isgraph_y1, isgraph(A));
59 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isgraph_y2, isgraph(a));
60 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isgraph_y3, isgraph(zero));
61 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isgraph_y4, isgraph(underscore));
62 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isgraph_n, isgraph(space));
63 
64 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_islower_y, islower(x));
65 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_islower_n, islower(X));
66 
67 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isprint_y1, isprint(A));
68 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isprint_y2, isprint(a));
69 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isprint_y3, isprint(zero));
70 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isprint_y4, isprint(underscore));
71 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isprint_y5, isprint(space));
72 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isprint_n, isprint(backspace));
73 
74 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_ispunct_y, ispunct(underscore));
75 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_ispunct_n, ispunct(A));
76 
77 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isspace_y1, isspace(space));
78 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isspace_y2, isspace(tab));
79 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isspace_n, isspace(A));
80 
81 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isupper_y, isupper(X));
82 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isupper_n, isupper(x));
83 
84 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isxdigit_y1, isxdigit(zero));
85 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isxdigit_y2, isxdigit(a));
86 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isxdigit_y3, isxdigit(A));
87 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_isxdigit_n, isxdigit(underscore));
88 
89 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_toascii_y, isascii(x));
90 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_toascii_n, isascii(top_bit_set));
91 
92 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_tolower_y, tolower(X));
93 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_tolower_n, tolower(x));
94 
95 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_toupper_y, toupper(x));
96 BIONIC_TRIVIAL_BENCHMARK(BM_ctype_toupper_n, toupper(X));
97