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