1 /* Measure strcat functions.
2 Copyright (C) 2013-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
21 # define TEST_NAME "strcat"
23 # define TEST_NAME "wcscat"
25 #include "bench-string.h"
28 # define STRCAT strcat
31 # define SIMPLE_STRCAT simple_strcat
32 # define STRLEN strlen
33 # define STRCMP strcmp
34 # define BIG_CHAR CHAR_MAX
35 # define SMALL_CHAR 127
38 # define STRCAT wcscat
41 # define SIMPLE_STRCAT simple_wcscat
42 # define STRLEN wcslen
43 # define STRCMP wcscmp
44 # define BIG_CHAR WCHAR_MAX
45 # define SMALL_CHAR 1273
49 typedef CHAR
*(*proto_t
) (CHAR
*, const CHAR
*);
50 CHAR
*SIMPLE_STRCAT (CHAR
*, const CHAR
*);
52 IMPL (SIMPLE_STRCAT
, 0)
56 SIMPLE_STRCAT (CHAR
*dst
, const CHAR
*src
)
59 while (*dst
++ != '\0');
61 while ((*dst
++ = *src
++) != '\0');
66 do_one_test (impl_t
*impl
, CHAR
*dst
, const CHAR
*src
)
68 size_t k
= STRLEN (dst
), i
, iters
= INNER_LOOP_ITERS
;
69 timing_t start
, stop
, cur
;
71 if (CALL (impl
, dst
, src
) != dst
)
73 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
74 CALL (impl
, dst
, src
), dst
);
79 if (STRCMP (dst
+ k
, src
) != 0)
81 error (0, 0, "Wrong result in function %s dst \"%" sfmt
"\" src \"%" sfmt
"\"",
82 impl
->name
, dst
, src
);
88 for (i
= 0; i
< iters
; ++i
)
91 CALL (impl
, dst
, src
);
95 TIMING_DIFF (cur
, start
, stop
);
97 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
101 do_test (size_t align1
, size_t align2
, size_t len1
, size_t len2
, int max_char
)
107 if ((align1
+ len1
) * sizeof (CHAR
) >= page_size
)
111 if ((align2
+ len1
+ len2
) * sizeof (CHAR
) >= page_size
)
114 s1
= (CHAR
*) (buf1
) + align1
;
115 s2
= (CHAR
*) (buf2
) + align2
;
117 for (i
= 0; i
< len1
; ++i
)
118 s1
[i
] = 32 + 23 * i
% (max_char
- 32);
121 for (i
= 0; i
< len2
; i
++)
122 s2
[i
] = 32 + 23 * i
% (max_char
- 32);
124 printf ("Length %4zd/%4zd, alignment %2zd/%2zd:", len1
, len2
, align1
, align2
);
126 FOR_EACH_IMPL (impl
, 0)
129 do_one_test (impl
, s2
, s1
);
143 FOR_EACH_IMPL (impl
, 0)
144 printf ("\t%s", impl
->name
);
147 for (i
= 0; i
< 16; ++i
)
149 do_test (0, 0, i
, i
, SMALL_CHAR
);
150 do_test (0, 0, i
, i
, BIG_CHAR
);
151 do_test (0, i
, i
, i
, SMALL_CHAR
);
152 do_test (i
, 0, i
, i
, BIG_CHAR
);
155 for (i
= 1; i
< 8; ++i
)
157 do_test (0, 0, 8 << i
, 8 << i
, SMALL_CHAR
);
158 do_test (8 - i
, 2 * i
, 8 << i
, 8 << i
, SMALL_CHAR
);
159 do_test (0, 0, 8 << i
, 2 << i
, SMALL_CHAR
);
160 do_test (8 - i
, 2 * i
, 8 << i
, 2 << i
, SMALL_CHAR
);
163 for (i
= 1; i
< 8; ++i
)
165 do_test (i
, 2 * i
, 8 << i
, 1, SMALL_CHAR
);
166 do_test (2 * i
, i
, 8 << i
, 1, BIG_CHAR
);
167 do_test (i
, i
, 8 << i
, 10, SMALL_CHAR
);
168 do_test (i
, i
, 8 << i
, 10, BIG_CHAR
);
174 #include "../test-skeleton.c"