Return failure in getnetgrent only when all netgroups have been searched (#17363)
[glibc.git] / benchtests / bench-strcat.c
blobfa21730c508c1406224c3af063e311b2c907583a
1 /* Measure strcat functions.
2 Copyright (C) 2013-2014 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), i, iters = INNER_LOOP_ITERS;
43 timing_t start, stop, cur;
45 if (CALL (impl, dst, src) != dst)
47 error (0, 0, "Wrong result in function %s %p %p", impl->name,
48 CALL (impl, dst, src), dst);
49 ret = 1;
50 return;
53 if (strcmp (dst + k, src) != 0)
55 error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
56 impl->name, dst, src);
57 ret = 1;
58 return;
61 TIMING_NOW (start);
62 for (i = 0; i < iters; ++i)
64 dst[k] = '\0';
65 CALL (impl, dst, src);
67 TIMING_NOW (stop);
69 TIMING_DIFF (cur, start, stop);
71 TIMING_PRINT_MEAN ((double) cur, (double) iters);
74 static void
75 do_test (size_t align1, size_t align2, size_t len1, size_t len2, int max_char)
77 size_t i;
78 char *s1, *s2;
80 align1 &= 7;
81 if (align1 + len1 >= page_size)
82 return;
84 align2 &= 7;
85 if (align2 + len1 + len2 >= page_size)
86 return;
88 s1 = (char *) (buf1 + align1);
89 s2 = (char *) (buf2 + align2);
91 for (i = 0; i < len1; ++i)
92 s1[i] = 32 + 23 * i % (max_char - 32);
93 s1[len1] = '\0';
95 for (i = 0; i < len2; i++)
96 s2[i] = 32 + 23 * i % (max_char - 32);
98 printf ("Length %4zd/%4zd, alignment %2zd/%2zd:", len1, len2, align1, align2);
100 FOR_EACH_IMPL (impl, 0)
102 s2[len2] = '\0';
103 do_one_test (impl, s2, s1);
106 putchar ('\n');
110 test_main (void)
112 size_t i;
114 test_init ();
116 printf ("%28s", "");
117 FOR_EACH_IMPL (impl, 0)
118 printf ("\t%s", impl->name);
119 putchar ('\n');
121 for (i = 0; i < 16; ++i)
123 do_test (0, 0, i, i, 127);
124 do_test (0, 0, i, i, 255);
125 do_test (0, i, i, i, 127);
126 do_test (i, 0, i, i, 255);
129 for (i = 1; i < 8; ++i)
131 do_test (0, 0, 8 << i, 8 << i, 127);
132 do_test (8 - i, 2 * i, 8 << i, 8 << i, 127);
133 do_test (0, 0, 8 << i, 2 << i, 127);
134 do_test (8 - i, 2 * i, 8 << i, 2 << i, 127);
137 for (i = 1; i < 8; ++i)
139 do_test (i, 2 * i, 8 << i, 1, 127);
140 do_test (2 * i, i, 8 << i, 1, 255);
141 do_test (i, i, 8 << i, 10, 127);
142 do_test (i, i, 8 << i, 10, 255);
145 return ret;
148 #include "../test-skeleton.c"