]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-memcpy.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / benchtests / bench-memcpy.c
CommitLineData
c1f75dc3 1/* Measure memcpy functions.
04277e02 2 Copyright (C) 2013-2019 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
5a82c748 17 <https://www.gnu.org/licenses/>. */
c1f75dc3
SP
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
3c05dd79 26void *generic_memcpy (void *, const void *, size_t);
c1f75dc3 27
16f87cfd 28IMPL (memcpy, 1)
3c05dd79 29IMPL (generic_memcpy, 0)
16f87cfd 30
c1f75dc3
SP
31#endif
32
5ee1e3ce
SP
33# include "json-lib.h"
34
3c05dd79 35typedef void *(*proto_t) (void *, const void *, size_t);
c1f75dc3
SP
36
37static void
5ee1e3ce 38do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
c1f75dc3
SP
39 size_t len)
40{
44558701
WN
41 size_t i, iters = INNER_LOOP_ITERS;
42 timing_t start, stop, cur;
43
44558701
WN
44 TIMING_NOW (start);
45 for (i = 0; i < iters; ++i)
c1f75dc3 46 {
44558701 47 CALL (impl, dst, src, len);
c1f75dc3 48 }
44558701
WN
49 TIMING_NOW (stop);
50
51 TIMING_DIFF (cur, start, stop);
52
5ee1e3ce 53 json_element_double (json_ctx, (double) cur / (double) iters);
c1f75dc3
SP
54}
55
56static void
5ee1e3ce 57do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len)
c1f75dc3
SP
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
5ee1e3ce
SP
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");
c1f75dc3
SP
81
82 FOR_EACH_IMPL (impl, 0)
5ee1e3ce 83 do_one_test (json_ctx, impl, s2, s1, len);
c1f75dc3 84
5ee1e3ce
SP
85 json_array_end (json_ctx);
86 json_element_object_end (json_ctx);
c1f75dc3
SP
87}
88
89int
90test_main (void)
91{
5ee1e3ce 92 json_ctx_t json_ctx;
c1f75dc3
SP
93 size_t i;
94
95 test_init ();
96
5ee1e3ce
SP
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");
7ee38e60 103 json_attr_object_begin (&json_ctx, TEST_NAME);
5ee1e3ce
SP
104 json_attr_string (&json_ctx, "bench-variant", "default");
105
106 json_array_begin (&json_ctx, "ifuncs");
c1f75dc3 107 FOR_EACH_IMPL (impl, 0)
5ee1e3ce
SP
108 json_element_string (&json_ctx, impl->name);
109 json_array_end (&json_ctx);
c1f75dc3 110
5ee1e3ce 111 json_array_begin (&json_ctx, "results");
c1f75dc3
SP
112 for (i = 0; i < 18; ++i)
113 {
5ee1e3ce
SP
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);
c1f75dc3
SP
118 }
119
120 for (i = 0; i < 32; ++i)
121 {
5ee1e3ce
SP
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);
c1f75dc3
SP
126 }
127
128 for (i = 3; i < 32; ++i)
129 {
130 if ((i & (i - 1)) == 0)
131 continue;
5ee1e3ce
SP
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);
c1f75dc3
SP
136 }
137
32b28d24
L
138 for (i = 32; i < 64; ++i)
139 {
5ee1e3ce
SP
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);
32b28d24
L
144 }
145
5ee1e3ce
SP
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);
c1f75dc3
SP
152
153 return ret;
154}
155
b598e134 156#include <support/test-driver.c>
3c05dd79
WD
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>