1 /* Measure strcat functions.
2 Copyright (C) 2013-2015 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/>. */
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)
30 simple_strcat (char *dst
, const char *src
)
33 while (*dst
++ != '\0');
35 while ((*dst
++ = *src
++) != '\0');
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
);
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
);
62 for (i
= 0; i
< iters
; ++i
)
65 CALL (impl
, dst
, src
);
69 TIMING_DIFF (cur
, start
, stop
);
71 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
75 do_test (size_t align1
, size_t align2
, size_t len1
, size_t len2
, int max_char
)
81 if (align1
+ len1
>= page_size
)
85 if (align2
+ len1
+ len2
>= page_size
)
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);
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)
103 do_one_test (impl
, s2
, s1
);
117 FOR_EACH_IMPL (impl
, 0)
118 printf ("\t%s", impl
->name
);
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);
148 #include "../test-skeleton.c"