conformtest: split up running of tests from makefile.
[glibc.git] / benchtests / bench-strtok.c
blobf2f3f575cde15c2097686fbb64d1fec08a51638e
1 /* Measure strtok 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 "strtok"
21 #include "bench-string.h"
23 #define STRTOK strtok_string
24 #include <string/strtok.c>
27 typedef char *(*proto_t) (const char *, const char *);
29 IMPL (strtok_string, 0)
30 IMPL (strtok, 1)
32 static void
33 do_one_test (impl_t * impl, const char *s1, const char *s2)
35 size_t i, iters = INNER_LOOP_ITERS;
36 timing_t start, stop, cur;
37 TIMING_NOW (start);
38 for (i = 0; i < iters; ++i)
40 CALL (impl, s1, s2);
41 CALL (impl, NULL, s2);
42 CALL (impl, NULL, s2);
44 TIMING_NOW (stop);
46 TIMING_DIFF (cur, start, stop);
48 TIMING_PRINT_MEAN ((double) cur, (double) iters);
53 static void
54 do_test (size_t align1, size_t align2, size_t len1, size_t len2, int fail)
56 char *s2 = (char *) (buf2 + align2);
57 static const char d[] = "1234567890abcdef";
58 #define dl (sizeof (d) - 1)
59 char *ss2 = s2;
60 for (size_t l = len2; l > 0; l = l > dl ? l - dl : 0)
62 size_t t = l > dl ? dl : l;
63 ss2 = mempcpy (ss2, d, t);
65 s2[len2] = '\0';
67 printf ("Length %4zd/%zd, alignment %2zd/%2zd, %s:",
68 len1, len2, align1, align2, fail ? "fail" : "found");
70 FOR_EACH_IMPL (impl, 0)
72 char *s1 = (char *) (buf1 + align1);
73 if (fail)
75 char *ss1 = s1;
76 for (size_t l = len1; l > 0; l = l > dl ? l - dl : 0)
78 size_t t = l > dl ? dl : l;
79 memcpy (ss1, d, t);
80 ++ss1[len2 > 7 ? 7 : len2 - 1];
81 ss1 += t;
84 else
86 memset (s1, '0', len1);
87 memcpy (s1 + (len1 - len2) - 2, s2, len2);
88 if ((len1 / len2) > 4)
89 memcpy (s1 + (len1 - len2) - (3 * len2), s2, len2);
91 s1[len1] = '\0';
92 do_one_test (impl, s1, s2);
94 putchar ('\n');
97 static int
98 test_main (void)
100 test_init ();
102 printf ("%23s", "");
103 FOR_EACH_IMPL (impl, 0)
104 printf ("\t%s", impl->name);
105 putchar ('\n');
107 for (size_t klen = 2; klen < 32; ++klen)
108 for (size_t hlen = 2 * klen; hlen < 16 * klen; hlen += klen)
110 do_test (0, 0, hlen, klen, 0);
111 do_test (0, 0, hlen, klen, 1);
112 do_test (0, 3, hlen, klen, 0);
113 do_test (0, 3, hlen, klen, 1);
114 do_test (0, 9, hlen, klen, 0);
115 do_test (0, 9, hlen, klen, 1);
116 do_test (0, 15, hlen, klen, 0);
117 do_test (0, 15, hlen, klen, 1);
119 do_test (3, 0, hlen, klen, 0);
120 do_test (3, 0, hlen, klen, 1);
121 do_test (3, 3, hlen, klen, 0);
122 do_test (3, 3, hlen, klen, 1);
123 do_test (3, 9, hlen, klen, 0);
124 do_test (3, 9, hlen, klen, 1);
125 do_test (3, 15, hlen, klen, 0);
126 do_test (3, 15, hlen, klen, 1);
128 do_test (9, 0, hlen, klen, 0);
129 do_test (9, 0, hlen, klen, 1);
130 do_test (9, 3, hlen, klen, 0);
131 do_test (9, 3, hlen, klen, 1);
132 do_test (9, 9, hlen, klen, 0);
133 do_test (9, 9, hlen, klen, 1);
134 do_test (9, 15, hlen, klen, 0);
135 do_test (9, 15, hlen, klen, 1);
137 do_test (15, 0, hlen, klen, 0);
138 do_test (15, 0, hlen, klen, 1);
139 do_test (15, 3, hlen, klen, 0);
140 do_test (15, 3, hlen, klen, 1);
141 do_test (15, 9, hlen, klen, 0);
142 do_test (15, 9, hlen, klen, 1);
143 do_test (15, 15, hlen, klen, 0);
144 do_test (15, 15, hlen, klen, 1);
146 do_test (0, 0, page_size - 1, 16, 0);
147 do_test (0, 0, page_size - 1, 16, 1);
149 return ret;
152 #include "../test-skeleton.c"