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/>. */
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
);
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
);
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
);
61 hp_timing_t start
__attribute ((unused
));
62 hp_timing_t stop
__attribute ((unused
));
63 hp_timing_t best_time
= ~ (hp_timing_t
) 0;
66 for (i
= 0; i
< 32; ++i
)
69 HP_TIMING_NOW (start
);
70 CALL (impl
, dst
, src
);
72 HP_TIMING_BEST (best_time
, start
, stop
);
75 printf ("\t%zd", (size_t) best_time
);
80 do_test (size_t align1
, size_t align2
, size_t len1
, size_t len2
, int max_char
)
86 if (align1
+ len1
>= page_size
)
90 if (align2
+ len1
+ len2
>= page_size
)
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);
100 for (i
= 0; i
< len2
; i
++)
101 s2
[i
] = 32 + 23 * i
% (max_char
- 32);
104 printf ("Length %4zd/%4zd, alignment %2zd/%2zd:", len1
, len2
, align1
, align2
);
106 FOR_EACH_IMPL (impl
, 0)
109 do_one_test (impl
, s2
, s1
);
124 FOR_EACH_IMPL (impl
, 0)
125 printf ("\t%s", impl
->name
);
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);
155 #include "../test-skeleton.c"