]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-memcpy.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / benchtests / bench-memcpy.c
CommitLineData
c1f75dc3 1/* Measure memcpy functions.
688903eb 2 Copyright (C) 2013-2018 Free Software Foundation, Inc.
c1f75dc3
SP
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#ifndef MEMCPY_RESULT
20# define MEMCPY_RESULT(dst, len) dst
21# define MIN_PAGE_SIZE 131072
22# define TEST_MAIN
23# define TEST_NAME "memcpy"
24# include "bench-string.h"
25
26char *simple_memcpy (char *, const char *, size_t);
27char *builtin_memcpy (char *, const char *, size_t);
28
29IMPL (simple_memcpy, 0)
30IMPL (builtin_memcpy, 0)
31IMPL (memcpy, 1)
32
33char *
34simple_memcpy (char *dst, const char *src, size_t n)
35{
36 char *ret = dst;
37 while (n--)
38 *dst++ = *src++;
39 return ret;
40}
41
42char *
43builtin_memcpy (char *dst, const char *src, size_t n)
44{
45 return __builtin_memcpy (dst, src, n);
46}
47#endif
48
5ee1e3ce
SP
49# include "json-lib.h"
50
c1f75dc3
SP
51typedef char *(*proto_t) (char *, const char *, size_t);
52
53static void
5ee1e3ce 54do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
c1f75dc3
SP
55 size_t len)
56{
44558701
WN
57 size_t i, iters = INNER_LOOP_ITERS;
58 timing_t start, stop, cur;
59
44558701
WN
60 TIMING_NOW (start);
61 for (i = 0; i < iters; ++i)
c1f75dc3 62 {
44558701 63 CALL (impl, dst, src, len);
c1f75dc3 64 }
44558701
WN
65 TIMING_NOW (stop);
66
67 TIMING_DIFF (cur, start, stop);
68
5ee1e3ce 69 json_element_double (json_ctx, (double) cur / (double) iters);
c1f75dc3
SP
70}
71
72static void
5ee1e3ce 73do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len)
c1f75dc3
SP
74{
75 size_t i, j;
76 char *s1, *s2;
77
78 align1 &= 63;
79 if (align1 + len >= page_size)
80 return;
81
82 align2 &= 63;
83 if (align2 + len >= page_size)
84 return;
85
86 s1 = (char *) (buf1 + align1);
87 s2 = (char *) (buf2 + align2);
88
89 for (i = 0, j = 1; i < len; i++, j += 23)
90 s1[i] = j;
91
5ee1e3ce
SP
92 json_element_object_begin (json_ctx);
93 json_attr_uint (json_ctx, "length", (double) len);
94 json_attr_uint (json_ctx, "align1", (double) align1);
95 json_attr_uint (json_ctx, "align2", (double) align2);
96 json_array_begin (json_ctx, "timings");
c1f75dc3
SP
97
98 FOR_EACH_IMPL (impl, 0)
5ee1e3ce 99 do_one_test (json_ctx, impl, s2, s1, len);
c1f75dc3 100
5ee1e3ce
SP
101 json_array_end (json_ctx);
102 json_element_object_end (json_ctx);
c1f75dc3
SP
103}
104
105int
106test_main (void)
107{
5ee1e3ce 108 json_ctx_t json_ctx;
c1f75dc3
SP
109 size_t i;
110
111 test_init ();
112
5ee1e3ce
SP
113 json_init (&json_ctx, 0, stdout);
114
115 json_document_begin (&json_ctx);
116 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
117
118 json_attr_object_begin (&json_ctx, "functions");
7ee38e60 119 json_attr_object_begin (&json_ctx, TEST_NAME);
5ee1e3ce
SP
120 json_attr_string (&json_ctx, "bench-variant", "default");
121
122 json_array_begin (&json_ctx, "ifuncs");
c1f75dc3 123 FOR_EACH_IMPL (impl, 0)
5ee1e3ce
SP
124 json_element_string (&json_ctx, impl->name);
125 json_array_end (&json_ctx);
c1f75dc3 126
5ee1e3ce 127 json_array_begin (&json_ctx, "results");
c1f75dc3
SP
128 for (i = 0; i < 18; ++i)
129 {
5ee1e3ce
SP
130 do_test (&json_ctx, 0, 0, 1 << i);
131 do_test (&json_ctx, i, 0, 1 << i);
132 do_test (&json_ctx, 0, i, 1 << i);
133 do_test (&json_ctx, i, i, 1 << i);
c1f75dc3
SP
134 }
135
136 for (i = 0; i < 32; ++i)
137 {
5ee1e3ce
SP
138 do_test (&json_ctx, 0, 0, i);
139 do_test (&json_ctx, i, 0, i);
140 do_test (&json_ctx, 0, i, i);
141 do_test (&json_ctx, i, i, i);
c1f75dc3
SP
142 }
143
144 for (i = 3; i < 32; ++i)
145 {
146 if ((i & (i - 1)) == 0)
147 continue;
5ee1e3ce
SP
148 do_test (&json_ctx, 0, 0, 16 * i);
149 do_test (&json_ctx, i, 0, 16 * i);
150 do_test (&json_ctx, 0, i, 16 * i);
151 do_test (&json_ctx, i, i, 16 * i);
c1f75dc3
SP
152 }
153
32b28d24
L
154 for (i = 32; i < 64; ++i)
155 {
5ee1e3ce
SP
156 do_test (&json_ctx, 0, 0, 32 * i);
157 do_test (&json_ctx, i, 0, 32 * i);
158 do_test (&json_ctx, 0, i, 32 * i);
159 do_test (&json_ctx, i, i, 32 * i);
32b28d24
L
160 }
161
5ee1e3ce
SP
162 do_test (&json_ctx, 0, 0, getpagesize ());
163
164 json_array_end (&json_ctx);
165 json_attr_object_end (&json_ctx);
166 json_attr_object_end (&json_ctx);
167 json_document_end (&json_ctx);
c1f75dc3
SP
168
169 return ret;
170}
171
b598e134 172#include <support/test-driver.c>