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