1 /* Measure strcpy functions.
2 Copyright (C) 2013-2020 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 <https://www.gnu.org/licenses/>. */
19 #define BIG_CHAR MAX_CHAR
23 # define SMALL_CHAR 1273
26 # define SMALL_CHAR 127
30 # define STRCPY_RESULT(dst, len) dst
33 # define TEST_NAME "strcpy"
35 # define TEST_NAME "wcscpy"
36 # define generic_strcpy generic_wcscpy
38 #include "bench-string.h"
41 generic_strcpy (CHAR
*dst
, const CHAR
*src
)
43 return MEMCPY (dst
, src
, STRLEN (src
) + 1);
47 IMPL (generic_strcpy
, 0)
51 typedef CHAR
*(*proto_t
) (CHAR
*, const CHAR
*);
54 do_one_test (impl_t
*impl
, CHAR
*dst
, const CHAR
*src
,
55 size_t len
__attribute__((unused
)))
57 size_t i
, iters
= INNER_LOOP_ITERS
;
58 timing_t start
, stop
, cur
;
60 if (CALL (impl
, dst
, src
) != STRCPY_RESULT (dst
, len
))
62 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
63 CALL (impl
, dst
, src
), STRCPY_RESULT (dst
, len
));
68 if (STRCMP (dst
, src
) != 0)
71 "Wrong result in function %s dst \"%" sfmt
"\" src \"%" sfmt
"\"",
72 impl
->name
, dst
, src
);
78 for (i
= 0; i
< iters
; ++i
)
80 CALL (impl
, dst
, src
);
84 TIMING_DIFF (cur
, start
, stop
);
86 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
90 do_test (size_t align1
, size_t align2
, size_t len
, int max_char
)
94 /* For wcscpy: align1 and align2 here mean alignment not in bytes,
95 but in wchar_ts, in bytes it will equal to align * (sizeof (wchar_t))
96 len for wcschr here isn't in bytes but it's number of wchar_t symbols. */
98 if ((align1
+ len
) * sizeof (CHAR
) >= page_size
)
102 if ((align2
+ len
) * sizeof (CHAR
) >= page_size
)
105 s1
= (CHAR
*) (buf1
) + align1
;
106 s2
= (CHAR
*) (buf2
) + align2
;
108 for (i
= 0; i
< len
; i
++)
109 s1
[i
] = 32 + 23 * i
% (max_char
- 32);
112 printf ("Length %4zd, alignments in bytes %2zd/%2zd:", len
,
113 align1
* sizeof (CHAR
), align2
* sizeof (CHAR
));
115 FOR_EACH_IMPL (impl
, 0)
116 do_one_test (impl
, s2
, s1
, len
);
129 FOR_EACH_IMPL (impl
, 0)
130 printf ("\t%s", impl
->name
);
133 for (i
= 0; i
< 16; ++i
)
135 do_test (0, 0, i
, SMALL_CHAR
);
136 do_test (0, 0, i
, BIG_CHAR
);
137 do_test (0, i
, i
, SMALL_CHAR
);
138 do_test (i
, 0, i
, BIG_CHAR
);
141 for (i
= 1; i
< 8; ++i
)
143 do_test (0, 0, 8 << i
, SMALL_CHAR
);
144 do_test (8 - i
, 2 * i
, 8 << i
, SMALL_CHAR
);
147 for (i
= 1; i
< 8; ++i
)
149 do_test (i
, 2 * i
, 8 << i
, SMALL_CHAR
);
150 do_test (2 * i
, i
, 8 << i
, BIG_CHAR
);
151 do_test (i
, i
, 8 << i
, SMALL_CHAR
);
152 do_test (i
, i
, 8 << i
, BIG_CHAR
);
155 for (i
= 16; i
<= 512; i
+=4)
157 do_test (0, 4, i
, SMALL_CHAR
);
158 do_test (4, 0, i
, BIG_CHAR
);
159 do_test (4, 4, i
, SMALL_CHAR
);
160 do_test (2, 2, i
, BIG_CHAR
);
161 do_test (2, 6, i
, SMALL_CHAR
);
162 do_test (6, 2, i
, BIG_CHAR
);
163 do_test (1, 7, i
, SMALL_CHAR
);
164 do_test (7, 1, i
, BIG_CHAR
);
165 do_test (3, 4, i
, SMALL_CHAR
);
166 do_test (4, 3, i
, BIG_CHAR
);
167 do_test (5, 7, i
, SMALL_CHAR
);
168 do_test (7, 5, i
, SMALL_CHAR
);
174 #include <support/test-driver.c>