Mention BZ #15674
[glibc.git] / benchtests / bench-strcat.c
blobb70a2721098500ddebd3c448fc2e348632aaf574
1 /* Measure strcat functions.
2 Copyright (C) 2013 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/>. */
19 #define TEST_MAIN
20 #define TEST_NAME "strcat"
21 #include "bench-string.h"
23 typedef char *(*proto_t) (char *, const char *);
24 char *simple_strcat (char *, const char *);
26 IMPL (simple_strcat, 0)
27 IMPL (strcat, 1)
29 char *
30 simple_strcat (char *dst, const char *src)
32 char *ret = dst;
33 while (*dst++ != '\0');
34 --dst;
35 while ((*dst++ = *src++) != '\0');
36 return ret;
39 static void
40 do_one_test (impl_t *impl, char *dst, const char *src)
42 size_t k = strlen (dst);
43 if (CALL (impl, dst, src) != dst)
45 error (0, 0, "Wrong result in function %s %p %p", impl->name,
46 CALL (impl, dst, src), dst);
47 ret = 1;
48 return;
51 if (strcmp (dst + k, src) != 0)
53 error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
54 impl->name, dst, src);
55 ret = 1;
56 return;
59 if (HP_TIMING_AVAIL)
61 hp_timing_t start __attribute ((unused));
62 hp_timing_t stop __attribute ((unused));
63 hp_timing_t best_time = ~ (hp_timing_t) 0;
64 size_t i;
66 for (i = 0; i < 32; ++i)
68 dst[k] = '\0';
69 HP_TIMING_NOW (start);
70 CALL (impl, dst, src);
71 HP_TIMING_NOW (stop);
72 HP_TIMING_BEST (best_time, start, stop);
75 printf ("\t%zd", (size_t) best_time);
79 static void
80 do_test (size_t align1, size_t align2, size_t len1, size_t len2, int max_char)
82 size_t i;
83 char *s1, *s2;
85 align1 &= 7;
86 if (align1 + len1 >= page_size)
87 return;
89 align2 &= 7;
90 if (align2 + len1 + len2 >= page_size)
91 return;
93 s1 = (char *) (buf1 + align1);
94 s2 = (char *) (buf2 + align2);
96 for (i = 0; i < len1; ++i)
97 s1[i] = 32 + 23 * i % (max_char - 32);
98 s1[len1] = '\0';
100 for (i = 0; i < len2; i++)
101 s2[i] = 32 + 23 * i % (max_char - 32);
103 if (HP_TIMING_AVAIL)
104 printf ("Length %4zd/%4zd, alignment %2zd/%2zd:", len1, len2, align1, align2);
106 FOR_EACH_IMPL (impl, 0)
108 s2[len2] = '\0';
109 do_one_test (impl, s2, s1);
112 if (HP_TIMING_AVAIL)
113 putchar ('\n');
117 test_main (void)
119 size_t i;
121 test_init ();
123 printf ("%28s", "");
124 FOR_EACH_IMPL (impl, 0)
125 printf ("\t%s", impl->name);
126 putchar ('\n');
128 for (i = 0; i < 16; ++i)
130 do_test (0, 0, i, i, 127);
131 do_test (0, 0, i, i, 255);
132 do_test (0, i, i, i, 127);
133 do_test (i, 0, i, i, 255);
136 for (i = 1; i < 8; ++i)
138 do_test (0, 0, 8 << i, 8 << i, 127);
139 do_test (8 - i, 2 * i, 8 << i, 8 << i, 127);
140 do_test (0, 0, 8 << i, 2 << i, 127);
141 do_test (8 - i, 2 * i, 8 << i, 2 << i, 127);
144 for (i = 1; i < 8; ++i)
146 do_test (i, 2 * i, 8 << i, 1, 127);
147 do_test (2 * i, i, 8 << i, 1, 255);
148 do_test (i, i, 8 << i, 10, 127);
149 do_test (i, i, 8 << i, 10, 255);
152 return ret;
155 #include "../test-skeleton.c"