]>
Commit | Line | Data |
---|---|---|
97020474 | 1 | /* Measure strcat functions. |
04277e02 | 2 | Copyright (C) 2013-2019 Free Software Foundation, Inc. |
97020474 SP |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
17 | <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #define TEST_MAIN | |
d626a24f SL |
20 | #ifndef WIDE |
21 | # define TEST_NAME "strcat" | |
22 | #else | |
23 | # define TEST_NAME "wcscat" | |
24 | #endif /* WIDE */ | |
97020474 SP |
25 | #include "bench-string.h" |
26 | ||
90d3320d WD |
27 | #define BIG_CHAR MAX_CHAR |
28 | ||
d626a24f | 29 | #ifndef WIDE |
d626a24f SL |
30 | # define sfmt "s" |
31 | # define SIMPLE_STRCAT simple_strcat | |
d626a24f SL |
32 | # define SMALL_CHAR 127 |
33 | #else | |
d626a24f SL |
34 | # define sfmt "ls" |
35 | # define SIMPLE_STRCAT simple_wcscat | |
d626a24f SL |
36 | # define SMALL_CHAR 1273 |
37 | #endif /* WIDE */ | |
38 | ||
39 | ||
40 | typedef CHAR *(*proto_t) (CHAR *, const CHAR *); | |
41 | CHAR *SIMPLE_STRCAT (CHAR *, const CHAR *); | |
42 | ||
43 | IMPL (SIMPLE_STRCAT, 0) | |
44 | IMPL (STRCAT, 1) | |
45 | ||
46 | CHAR * | |
47 | SIMPLE_STRCAT (CHAR *dst, const CHAR *src) | |
97020474 | 48 | { |
d626a24f | 49 | CHAR *ret = dst; |
97020474 SP |
50 | while (*dst++ != '\0'); |
51 | --dst; | |
52 | while ((*dst++ = *src++) != '\0'); | |
53 | return ret; | |
54 | } | |
55 | ||
56 | static void | |
d626a24f | 57 | do_one_test (impl_t *impl, CHAR *dst, const CHAR *src) |
97020474 | 58 | { |
d626a24f | 59 | size_t k = STRLEN (dst), i, iters = INNER_LOOP_ITERS; |
44558701 WN |
60 | timing_t start, stop, cur; |
61 | ||
97020474 SP |
62 | if (CALL (impl, dst, src) != dst) |
63 | { | |
64 | error (0, 0, "Wrong result in function %s %p %p", impl->name, | |
65 | CALL (impl, dst, src), dst); | |
66 | ret = 1; | |
67 | return; | |
68 | } | |
69 | ||
d626a24f | 70 | if (STRCMP (dst + k, src) != 0) |
97020474 | 71 | { |
d626a24f | 72 | error (0, 0, "Wrong result in function %s dst \"%" sfmt "\" src \"%" sfmt "\"", |
97020474 SP |
73 | impl->name, dst, src); |
74 | ret = 1; | |
75 | return; | |
76 | } | |
77 | ||
44558701 WN |
78 | TIMING_NOW (start); |
79 | for (i = 0; i < iters; ++i) | |
97020474 | 80 | { |
44558701 WN |
81 | dst[k] = '\0'; |
82 | CALL (impl, dst, src); | |
97020474 | 83 | } |
44558701 WN |
84 | TIMING_NOW (stop); |
85 | ||
86 | TIMING_DIFF (cur, start, stop); | |
87 | ||
88 | TIMING_PRINT_MEAN ((double) cur, (double) iters); | |
97020474 SP |
89 | } |
90 | ||
91 | static void | |
92 | do_test (size_t align1, size_t align2, size_t len1, size_t len2, int max_char) | |
93 | { | |
94 | size_t i; | |
d626a24f | 95 | CHAR *s1, *s2; |
97020474 SP |
96 | |
97 | align1 &= 7; | |
d626a24f | 98 | if ((align1 + len1) * sizeof (CHAR) >= page_size) |
97020474 SP |
99 | return; |
100 | ||
101 | align2 &= 7; | |
d626a24f | 102 | if ((align2 + len1 + len2) * sizeof (CHAR) >= page_size) |
97020474 SP |
103 | return; |
104 | ||
d626a24f SL |
105 | s1 = (CHAR *) (buf1) + align1; |
106 | s2 = (CHAR *) (buf2) + align2; | |
97020474 SP |
107 | |
108 | for (i = 0; i < len1; ++i) | |
109 | s1[i] = 32 + 23 * i % (max_char - 32); | |
110 | s1[len1] = '\0'; | |
111 | ||
112 | for (i = 0; i < len2; i++) | |
113 | s2[i] = 32 + 23 * i % (max_char - 32); | |
114 | ||
44558701 | 115 | printf ("Length %4zd/%4zd, alignment %2zd/%2zd:", len1, len2, align1, align2); |
97020474 SP |
116 | |
117 | FOR_EACH_IMPL (impl, 0) | |
118 | { | |
119 | s2[len2] = '\0'; | |
120 | do_one_test (impl, s2, s1); | |
121 | } | |
122 | ||
44558701 | 123 | putchar ('\n'); |
97020474 SP |
124 | } |
125 | ||
126 | int | |
127 | test_main (void) | |
128 | { | |
129 | size_t i; | |
130 | ||
131 | test_init (); | |
132 | ||
133 | printf ("%28s", ""); | |
134 | FOR_EACH_IMPL (impl, 0) | |
135 | printf ("\t%s", impl->name); | |
136 | putchar ('\n'); | |
137 | ||
138 | for (i = 0; i < 16; ++i) | |
139 | { | |
d626a24f SL |
140 | do_test (0, 0, i, i, SMALL_CHAR); |
141 | do_test (0, 0, i, i, BIG_CHAR); | |
142 | do_test (0, i, i, i, SMALL_CHAR); | |
143 | do_test (i, 0, i, i, BIG_CHAR); | |
97020474 SP |
144 | } |
145 | ||
146 | for (i = 1; i < 8; ++i) | |
147 | { | |
d626a24f SL |
148 | do_test (0, 0, 8 << i, 8 << i, SMALL_CHAR); |
149 | do_test (8 - i, 2 * i, 8 << i, 8 << i, SMALL_CHAR); | |
150 | do_test (0, 0, 8 << i, 2 << i, SMALL_CHAR); | |
151 | do_test (8 - i, 2 * i, 8 << i, 2 << i, SMALL_CHAR); | |
97020474 SP |
152 | } |
153 | ||
154 | for (i = 1; i < 8; ++i) | |
155 | { | |
d626a24f SL |
156 | do_test (i, 2 * i, 8 << i, 1, SMALL_CHAR); |
157 | do_test (2 * i, i, 8 << i, 1, BIG_CHAR); | |
158 | do_test (i, i, 8 << i, 10, SMALL_CHAR); | |
159 | do_test (i, i, 8 << i, 10, BIG_CHAR); | |
97020474 SP |
160 | } |
161 | ||
162 | return ret; | |
163 | } | |
164 | ||
b598e134 | 165 | #include <support/test-driver.c> |